﻿---@diagnostic disable: trailing-space
local extension = Package:new("moepack")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack"] = "萌包",
  ["moe"] = "萌",
}

local U = require "packages/utility/utility"

local MoeFunc = require "packages/moepack/moepack_function"

--[[
    测试
]]--
local emotest = General(extension, "emotest", "moe", 8, 8, General.Female)
emotest.hidden = true
--emotest.total_hidden = true


local emo__cheat = fk.CreateActiveSkill{
  name = "emo__cheat",
  anim_type = "drawcard",
  prompt = "#emo__cheat",
  can_use = Util.TrueFunc,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local types = { "basic", "trick", "equip" , "derived_card", "ban_cards" }
    local cardType = room:askForChoice(player, types, self.name)
    local allCardMapper = {}
    local allCardNames = {}
    if cardType ~= "ban_cards" then
      for _, id in ipairs(Fk:getAllCardIds()) do
        local card = Fk:getCardById(id)
        if card:getTypeString() == cardType or (card.is_derived and cardType == "derived_card") then
          if allCardMapper[card.name] == nil then
            allCardMapper[card.name] = {}
            table.insert(allCardNames, card.name)
          end
          table.insert(allCardMapper[card.name], id)
        end
      end
    else
      local packageMap, packages = {}, {}
      for _, name in ipairs(Fk.all_card_names) do
        local card = Fk:cloneCard(name)
        if card.package and table.contains(room.disabled_packs, card.package.name) then
          if packageMap[card.package.name] == nil then
            packageMap[card.package.name] = {}
            table.insert(packages, card.package.name)
          end
          table.insert(packageMap[card.package.name], name)
        end
      end
      if #packages == 0 then return end
      local pack = room:askForChoice(player, packages, self.name)
      allCardNames = packageMap[pack]
    end

    if #allCardNames == 0 then
      return
    end
    local cardName = room:askForChoice(player, allCardNames, self.name)
    local get = table.filter(allCardMapper[cardName] or {}, function(id) return room:getCardOwner(id) == nil end)
    if #get > 0 then
      get = table.random(get)
    else
      get = room:printCard(cardName, math.random(4), math.random(13)).id
    end
    room:obtainCard(player, get, true, fk.ReasonPrey, player.id, self.name)

  end
}
emotest:addSkill(emo__cheat)

local emo__damage_maker = fk.CreateActiveSkill{
  name = "emo__damage_maker",
  anim_type = "offensive",
  prompt = "#emo__damage_maker",
  can_use = function(self, player)
    return true
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_filter = function(self, to_select, selected)
    if self.interaction.data == "revive" then return false end
    return #selected < 2
  end,
  min_target_num = function(self)
    return self.interaction.data == "revive" and 0 or 1
  end,
  max_target_num = function(self)
    return self.interaction.data == "revive" and 0 or 2
  end,
  interaction = function (self, player)
    local choices = {"normal_damage"}
    for _, v in pairs(Fk:getDamageNatures()) do
      table.insertIfNeed(choices, v[1])
    end
    table.insertTable(choices, {
      "virtual_damage", "lose_hp", "heal_hp", "lose_max_hp", "heal_max_hp", "changeShield",
      "revive", "death"
    })
    return UI.ComboBox {
      choices = choices
    } 
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local victim = #effect.tos > 0 and room:getPlayerById(effect.tos[1])
    local target = #effect.tos > 1 and room:getPlayerById(effect.tos[2])
    local choice = self.interaction.data
    local number
    if choice == "changeShield" then
      local choices = {}
      for i = - (math.min(5, victim.shield)), 5 do
        table.insert(choices, tostring(i))
      end
      table.removeOne(choices, "0")
      number = tonumber(room:askForChoice(from, choices, self.name, nil))
    elseif choice ~= "revive" and choice ~= "death" then
      local choices = {}
      for i = 1, 99 do
        table.insert(choices, tostring(i))
      end
      number = tonumber(room:askForChoice(from, choices, self.name, nil))
    end
    if target then from = target end -- ?
    if choice == "heal_hp" then
      room:recover{
        who = victim,
        num = number,
        recoverBy = from,
        skillName = self.name
      }
    elseif choice == "heal_max_hp" then
      room:changeMaxHp(victim, number)
    elseif choice == "lose_max_hp" then
      room:changeMaxHp(victim, -number)
    elseif choice == "lose_hp" then
      room:loseHp(victim, number, self.name)
    elseif choice == "changeShield" then
      room:changeShield(victim, number)
    elseif choice == "death" then
      room:killPlayer({ who = victim.id })
    elseif choice == "revive" then
      local targets = table.map(table.filter(room.players, function(p) return p.dead end), function(p) return "seat#" .. tostring(p.seat) end)
      if #targets > 0 then
        targets = room:askForChoice(from, targets, self.name, "#revive-ask")
        if targets then
          target = tonumber(string.sub(targets, 6))
          for _, p in ipairs(room.players) do
            if p.seat == target then
              room:revivePlayer(p, true)
              break
            end
          end
        end
      end
    else -- damage
      local choices = {"normal_damage", "thunder_damage", "fire_damage", "ice_damage"}
      local damageType = fk.NormalDamage
      for damageT, v in pairs(Fk:getDamageNatures()) do
        if v[1] == choice then
          damageType = damageT
          break
        end
      end
      room:damage({
        from = from,
        to = victim,
        damage = number,
        damageType = damageType,
        isVirtualDMG = choice == "virtual_damage",
        skillName = self.name
      })
    end
  end,
}
emotest:addSkill(emo__damage_maker)

local emo__change_hero = fk.CreateActiveSkill{
  name = "emo__change_hero",
  can_use = Util.TrueFunc,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_filter = function(self, to_select, selected)
    local choice = self.interaction.data
    if table.contains({"emo_change_role", "emo_change_kingdom", "skip_turn"}, choice) then return true end
    return #selected < 1
  end,
  min_target_num = 0,
  interaction = function()
    return UI.ComboBox {  
      choices = { 
        "mainGeneral",  "deputyGeneral", "emo_use_slash", "emo_change_role", "emo_change_kingdom", "delete_skills",
        "abort_resume_area", "skip_turn",
      }
    }
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = #effect.tos == 0 and player or room:getPlayerById(effect.tos[1])
    local tos = table.map(effect.tos, Util.Id2PlayerMapper)
    local choice = self.interaction.data
    if choice == "emo_use_slash" then
      room:setPlayerMark(target, MarkEnum.SlashBypassTimes.."-turn", 1)
      room:setPlayerMark(target, MarkEnum.SlashBypassDistances.."-turn", 1)
      local ids = room:getCardsFromPileByRule("slash", 5, "allPiles")
      if #ids > 0 then
        room:obtainCard(target, ids, false, fk.ReasonPrey)
      end
    elseif choice == "emo_change_role" then
      local roles = {"lord", "loyalist", "rebel", "renegade"}
      -- 房间可能有奇怪的身份
      for _, p in ipairs(room.players) do
        table.insertIfNeed(roles, p.role)
      end
      local role = room:askForChoice(player, roles, self.name)
      if role == "lord" then
        for _, p in ipairs(room.alive_players) do
          if p.role == "lord" and not table.contains(tos, p) then
            room:setPlayerProperty(p, "role", "renegade")
          end
        end
      end
      for _, p in ipairs(tos) do
        room:setPlayerProperty(p, "role", role)
        if role == "lord" then
          room:setPlayerProperty(p, "role_shown", true)
        end
      end
    elseif choice == "emo_change_kingdom" then
      local kingdoms = {"wei","shu","wu","qun","jin","god","moe"}
      for _, g in pairs(Fk.generals) do
        table.insertIfNeed(kingdoms, g.kingdom)
      end
      if #kingdoms == 0 then return end
      local kingdom = room:askForChoice(player, kingdoms, self.name)
      for _, p in ipairs(tos) do
        room:changeKingdom(p, kingdom)
      end
    elseif choice == "skip_turn" then
      for _, p in ipairs(tos) do
        room:setPlayerMark(p, "@@skip_turn", 1 - p:getMark("@@skip_turn"))
      end
    elseif choice == "delete_skills" then
      local skills = table.map(target.player_skills, function(s) return s.name end)
      if #skills == 0 then return end
      local to_delete = room:askForChoices(player, skills, 0, 999, self.name)
      if #to_delete > 0 then
        room:handleAddLoseSkills(target, "-"..table.concat(to_delete, "|-"))
      end
    elseif choice == "abort_resume_area" then
      local choices = table.simpleClone(target.equipSlots)
      table.insert(choices, Player.JudgeSlot)
      if #choices == 0 then return end
      choices = room:askForChoices(player, choices, 1, 999, self.name, nil, false)
      for _, slot in ipairs(choices) do
        if target.dead then break end
        if table.contains(target.sealedSlots, slot) then
          room:resumePlayerArea(target, slot)
        else
          room:abortPlayerArea(target, slot)
        end
      end
    else -- change hero
      local commonlyGenerals = {"xuyou", "yangxiu", "ex__xiahoudun", "sunwukong", "zhoubuyi", "js__guanyu", "y13__caoren", "zhupeilan"}
      local generals = table.filter(commonlyGenerals, function (g) return Fk.generals[g] ~= nil end)
      local rest = 9 - #generals
      if rest > 0 then
        table.insertTable(generals, table.random(room.general_pile, rest))
      end
      local general = room:askForGeneral(player, generals, 1)
      local skills = Fk.generals[general]:getSkillNameList(true)
      if target == player then
        room:setPlayerGeneral(player, general, true)
        room:handleAddLoseSkills(target, table.concat(skills, "|"))
      else
        room:changeHero(target, general, false, choice == "deputyGeneral", true)
      end
      for _, sname in ipairs(skills) do
        local s = Fk.skills[sname]
        if not s:isInstanceOf(TriggerSkill) then
          for _, _s in ipairs(s.related_skills) do
            if  _s:isInstanceOf(TriggerSkill) then
              s = _s
              break
            end
          end
        end
        if s:isInstanceOf(TriggerSkill) and type(s.events) == "table" then
          local events = {fk.GamePrepared, fk.GameStart}
          for _, e in ipairs(events) do
            if table.contains(s.events, e) then
              if s:triggerable(e, target, target, nil) then
                s:trigger(e, target, target, nil)
              end
            end
          end
        end
      end
    end
  end,
}

local emo__change_hero_trigger = fk.CreateTriggerSkill{
  name = "#emo__change_hero_trigger",
  mute = true,
  priority = 10,
  frequency = Skill.Compulsory,
  events = {fk.PreTurnStart},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:getMark("@@skip_turn") > 0
  end,
  on_use = function (self, event, target, player, data)
    if table.every(player.room.alive_players, function(p) return p:getMark("@@skip_turn") > 0 end) then
      player.room:setPlayerMark(player, "@@skip_turn", 0)
    end
    return true
  end,
}
emo__change_hero:addRelatedSkill(emo__change_hero_trigger)

emotest:addSkill(emo__change_hero)

local emo__control = fk.CreateActiveSkill{
  name = "emo__control",
  anim_type = "control",
  can_use = Util.TrueFunc,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  min_target_num = 1,
  prompt = "#emo__control-prompt",
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    for _, pid in ipairs(effect.tos) do
      local to = room:getPlayerById(pid)
      if to.serverplayer ~= player._splayer then
        player:control(to)
      else
        to:control(to)
      end
    end
  end,
}
emotest:addSkill(emo__control)

local emo__xunce = fk.CreateTriggerSkill{
  name = "emo__xunce",
  events = {fk.GamePrepared, fk.EventPhaseSkipping, fk.EventPhaseChanging, fk.BeforeGameOverJudge},
  priority = 2,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.GamePrepared then
      return player:hasSkill(self,true)
    elseif event == fk.EventPhaseSkipping then
      return player:hasSkill(self,true) and target == player and player.phase > 1 and player.phase < 8
    elseif event == fk.EventPhaseChanging then
      return player:hasSkill(self,true) and target == player and data.to == Player.Judge and #player:getCardIds("j") > 0
    else
      return player:hasSkill(self,true,true) and (target == player or #player.room.alive_players == 1)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GamePrepared then
      local first = table.find(room.players, function(p) return p.seat == 1 end)
      if first and first ~= player then
        room:swapSeat(player, first)
        room:setCurrent(player)
      end
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if p.id < 0 then
          player:control(p)
        end
      end
    elseif event == fk.EventPhaseSkipping then
      local list = { "phase_start","phase_judge","phase_draw","phase_play","phase_discard","phase_finish"}
      local phase = list[player.phase - 1]
      return room:askForSkillInvoke(player, self.name, nil, "#emo__xunce-skip:::"..phase)
    elseif event == fk.EventPhaseChanging then
      if room:askForSkillInvoke(player, self.name, nil, "#emo__xunce-throwjudge") then
        room:moveCardTo(player:getCardIds("j"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
      end
    elseif event == fk.BeforeGameOverJudge then
      if room.settings.gameMode == "m_1v1_mode" then
        return
      end
      if target == player then
        if player.maxHp < 1 then
          room:setPlayerProperty(player, "maxHp", 5)
        end
        room:revivePlayer(player, true)
      else
        for _, p in ipairs(room.players) do
          room:revivePlayer(p, false)
        end
      end
    end
  end,
}
local emo__xunce2 = fk.CreateTriggerSkill{
  name = "#emo__xunce2",
  refresh_events = {fk.GameOverJudge},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true, true)
  end,
  on_refresh = function(self, event, target, player, data)
    -- 防止结束游戏
    player.room:setTag("SkipGameRule", true)
  end,
}
emo__xunce:addRelatedSkill(emo__xunce2)
emotest:addSkill(emo__xunce)

local emo__wozhu = fk.CreateTriggerSkill{
  name = "emo__wozhu",
  events = {fk.GamePrepared},
  priority = 10,
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 禁止多人PVP使用
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if p.serverplayer:getState() == fk.Player_Online and p.id > 10 then
        room:changeHero(player, "sunce", true)
        room:changeHero(player, "yujin", true, true)
      end
    end
    local lord = table.find(room.alive_players, function(p) return p.role == "lord" end)
    local skills = {}
    for _, skill_name in ipairs(Fk.generals[player.general]:getSkillNameList(true)) do
      local skill = Fk.skills[skill_name]
      if skill.lordSkill then
        table.insertIfNeed(skills, skill_name)
      end
    end
    if player.deputyGeneral ~= "" then
      for _, skill_name in ipairs(Fk.generals[player.deputyGeneral]:getSkillNameList(true)) do
        local skill = Fk.skills[skill_name]
        if skill.lordSkill then
          table.insertIfNeed(skills, skill_name)
        end
      end
    end
    for _, skill_name in ipairs(skills) do
      room:handleAddLoseSkills(player, skill_name, nil, false)
    end
    for _, p in ipairs(room:getOtherPlayers(player)) do
      room:setPlayerProperty(p, "kingdom", player.kingdom)
    end
  end,
}
emotest:addSkill(emo__wozhu)

local emo__rende = fk.CreateActiveSkill{
  name = "emo__rende",
  anim_type = "support",
  interaction = function()
    return UI.ComboBox {choices = {"emo__rende", "emo__rende_use", "emo__rende_put", "emo__rende_prey",
      "emo__rende_top", "emo__rende_bottom", "emo__rende_throw", "emo__rende_draw",
    }}
  end,
  card_filter = function(self, to_select, selected)
    local choice = self.interaction.data
    if table.contains({"emo__rende_prey", "emo__rende_draw"}, choice) then return false end
    if choice == "emo__rende_put" then
      return Fk:getCardById(to_select).type == Card.TypeEquip and table.every(selected, function (id)
        return Fk:getCardById(to_select).sub_type ~= Fk:getCardById(id).sub_type
      end)
    end
    if choice == "emo__rende_throw" and Self:prohibitDiscard(to_select) then return false end
    return true
  end,
  target_filter = function(self, to_select, selected)
    local choice = self.interaction.data
    if table.contains({"emo__rende_top", "emo__rende_bottom", "emo__rende_throw"}, choice) then return false end
    if choice == "emo__rende_draw" then return true end
    return #selected == 0 and to_select ~= Self.id
  end,
  feasible = function(self, selected, selected_cards)
    local choice = self.interaction.data
    if table.contains({"emo__rende_top", "emo__rende_bottom", "emo__rende_throw"}, choice) then
      return #selected_cards > 0
    elseif table.contains({"emo__rende_prey", "emo__rende_draw"}, choice) then
      return #selected > 0
    else
      return #selected_cards > 0 and #selected > 0
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local choice = self.interaction.data
    if choice == "emo__rende_top" then
      local cards = effect.cards
      if #cards > 1 then
        cards = room:askForGuanxing(player, cards, nil, {0,0}, self.name, true).top
      end
      if #cards > 0 then
        room:moveCards({
          ids = table.reverse(cards),
          from = player.id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
          proposer = player.id,
        })
      end
    elseif choice == "emo__rende_bottom" then
      local cards = effect.cards
      --[[if #cards > 1 then
        cards = room:askForGuanxing(player, cards, {0,0}, nil, self.name, true).bottom
      end--]]
      if #cards > 0 then
        room:moveCards({
          ids = table.reverse(cards),
          from = player.id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
          proposer = player.id,
          drawPilePosition = #room.draw_pile + 1,
        })
      end
    elseif choice == "emo__rende_throw" then
      room:throwCard(effect.cards, self.name, player, player)
    elseif choice == "emo__rende_draw" then
      local choices = {}
      for i = 1, 9 do
        table.insert(choices, tostring(i))
      end
      for i = 1, #room.draw_pile // 10  do
        table.insert(choices, tostring(i * 10))
      end
      for i = 1, #room.draw_pile // 100 do
        table.insert(choices, tostring(i * 100))
      end
      table.insertIfNeed(choices, tostring(#room.draw_pile))
      local n = room:askForChoice(player, choices, self.name)
      for _, pid in ipairs(effect.tos) do
        local to = room:getPlayerById(pid)
        if not to.dead then
          to:drawCards(tonumber(n), self.name)
        end
      end
    elseif choice == "emo__rende_prey" then
      local target = room:getPlayerById(effect.tos[1])
      local all_cards = target:getCardIds("hej")
      if #all_cards == 0 then return end
      local cards, ch = U.askforChooseCardsAndChoice(player, all_cards, {"OK"}, self.name, "", {"All"}, 1, 9999)
      if ch == "All" then
        cards = all_cards
      end
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
    else
      local target = room:getPlayerById(effect.tos[1])
      local cards = effect.cards
      if self.interaction.data ~= "emo__rende_put" then
        room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, self.name, nil, false, player.id)
        if self.interaction.data == "emo__rende_use" then
          U.askForUseRealCard(room, target, cards, nil, self.name)
        end
      else
        room:moveCardIntoEquip(target, cards, self.name, true, player)
      end
    end
  end,
}

emotest:addSkill(emo__rende)

emotest:addSkill("guicai")
emotest:addSkill("test_kansha")






Fk:loadTranslationTable{
  ["emotest"] = "测试",

  ["emo__cheat"] = "小开",
  [":emo__cheat"] = "出牌阶段，你可获得想要的牌（包括衍生牌）。",
  ["#emo__cheat"] = "小开：你可以获得一张想要的牌",
  ["normal_card"] = "普通牌",
  ["derived_card"] = "衍生牌",
  ["ban_cards"] = "禁卡",

  ["emo__control"] = "控制",
  [":emo__control"] = "出牌阶段，你可以控制/解除控制若干名其他角色。",
  ["#emo__control-prompt"] = "控制：控制/解除控制若干名其他角色",

  ["emo__damage_maker"] = "制伤",
  [":emo__damage_maker"] = "出牌阶段，你可以进行一次伤害制造器。",
  ["#emo__damage_maker"] = "制伤：选择一名小白鼠，可选另一名角色做伤害来源（默认为自己）",
  ["#revive-ask"] = "复活一名角色！",
  ["virtual_damage"] = "虚拟伤害",

  ["emo__xunce"] = "迅测",
  [":emo__xunce"] = "锁定技，游戏开始时，你变为一号位，并控制所有AI。判定阶段开始前，若你判定区有牌，你可以弃置之。当你跳过阶段时，可以防止之。你不会死亡，最后一名其他角色死亡时，复活所有其他角色。游戏结束前防止之。",
  ["#emo__xunce-skip"] = "迅测：你可以防止你跳过 %arg",
  ["#emo__xunce-throwjudge"] = "迅测：你可以将判定区的牌置入弃牌堆！",

  ["emo__change_hero"] = "变更",
  [":emo__change_hero"] = "出牌阶段，你可以变更一名角色武将牌（你不会因此失去技能），若其获得了时机为“游戏开始时”的技能，触发之。出牌阶段，你可以令一名角色摸五张【杀】且本回合使用【杀】无距离和次数限制。出牌阶段，你可以删除一名角色的任意技能（包括附加和装备技能），或令其废除/恢复判定区或任意装备栏，或令其始终跳过回合。",
  ["emo_use_slash"] = "用杀",
  ["emo_change_role"] = "改变身份",
  ["emo_change_kingdom"] = "改变势力",
  ["delete_skills"] = "删除技能",
  ["abort_resume_area"] = "废除/恢复区域",
  ["skip_turn"] = "跳过回合",
  ["@@skip_turn"] = "跳过回合",

  ["emo__wozhu"] = "我主",
  [":emo__wozhu"] = "锁定技，游戏开始时，若存在其他人类玩家，将你变成孙策/于禁，否则，你获得你武将牌上的主公技，然后将所有其他角色变为与你势力相同。",

  ["emo__rende"] = "仁德",
  [":emo__rende"] = "出牌阶段，你可以将任意张牌交给一名角色，且可以令其使用之，或将装备牌置入其装备区。或将任意牌置于牌堆顶。或弃置任意张牌并摸等量张牌。或获得一名角色任意张牌。或令一名角色摸牌。",
  ["emo__rende_use"] = "给牌并用牌",
  ["emo__rende_put"] = "置入装备区",
  ["emo__rende_top"] = "置于牌堆顶",
  ["emo__rende_bottom"] = "置于牌堆底",
  ["emo__rende_throw"] = "弃置",
  ["emo__rende_prey"] = "获得牌",
  ["emo__rende_draw"] = "摸牌",

  ["lose_hp"] = "失去体力",
  ["heal_hp"] = "回复体力",
  ["lose_max_hp"] = "扣减体力上限",
  ["heal_max_hp"] = "增加体力上限",
  ["revive"] = "复活",
  ["changeShield"] = "改变护甲",
  ["death"] = "死亡",
}



--[[

    武将一览

]]--



local moe__emoprincess = General(extension, "moe__emoprincess", "moe", 3, 3, General.Female)

local emo__zhiqi = fk.CreateActiveSkill{
  name = "emo__zhiqi",
  anim_type = "drawcard",
  prompt = "#emo__zhiqi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 4
  end,
  target_num = 0,
  target_filter = Util.TrueFunc,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and (Fk:getCardById(to_select).trueName == "slash" or Fk:getCardById(to_select).trueName == "jink")
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cardtype = Fk:getCardById(effect.cards[1]).trueName == "slash" and "trick" or "equip"
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    room:addPlayerMark(player, "emozhiqiCount-phase", 1)
    local x = player:getMark("emozhiqiCount-phase")
    local ids = room:getCardsFromPileByRule(".|.|.|.|.|"..cardtype, x)
    if #ids == 0 then return false end
    local get = table.random(ids)
    if #ids > 1 then
      local result = room:askForGuanxing(player, ids, nil, {1, 1}, self.name, true, {"Pile", "emozhiqiGet"})
      if #result.bottom > 0 then get = result.bottom[1] end
    end
    local targetId = player.id
    local tos = room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emoziqi-give:::"..Fk:getCardById(get):toLogString(), self.name, true)
    if #tos > 0 then
      targetId = tos[1]
      room:addPlayerMark(player, "emozhiqiCount-phase", 1)
    end
    room:obtainCard(targetId, get, false, fk.ReasonPrey)
  end,
}
moe__emoprincess:addSkill(emo__zhiqi)

local emo__jisi = fk.CreateTriggerSkill{
  name = "emo__jisi",
  anim_type = "drawcard",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return #player:getTableMark("@emo__jisi_Record") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getMark("@emo__jisi_Record")
    room:setPlayerMark(player, "@emo__jisi_Record", 0)
    local cardsMap = {}
    for _, id in ipairs(room.draw_pile) do
      local suit = Fk:getCardById(id):getSuitString(true)
      if table.contains(mark, suit) then
        cardsMap[suit] = cardsMap[suit] or {}
        table.insert(cardsMap[suit], id)
      end
    end
    local cards = U.getRandomCards(cardsMap, 4)
    if #cards > 0 then
      room:obtainCard(player, cards, false, fk.ReasonPrey, player.id, self.name)
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and #player:getTableMark("@emo__jisi_Record") < 4
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@emo__jisi_Record")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile and move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResonpse then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if card.suit ~= Card.NoSuit then
            table.insertIfNeed(mark, card:getSuitString(true))
          end
        end
      end
    end
    room:setPlayerMark(player, "@emo__jisi_Record", #mark > 0 and mark or 0)
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@emo__jisi_Record", 0)
  end,
}
moe__emoprincess:addSkill(emo__jisi)

Fk:loadTranslationTable{
  ["moe__emoprincess"] = "依默公主",

  ["emo__zhiqi"] = "置奇",
  [":emo__zhiqi"] = "出牌阶段限四次，你可以弃置一张【杀】/【闪】，从牌堆随机X张锦囊牌/装备牌中选择一张交给一名角色，然后若该角色不为你，本阶段X的值视为+1（X为你本阶段以此法弃置的牌数）。",
  ["#emo__zhiqi"] = "置奇：弃置【杀】检索锦囊牌 / 弃置【闪】检索装备牌",
  ["emozhiqiGet"] = "获得",
  ["#emoziqi-give"] = "置奇：将 %arg 交给一名角色，点“取消”交给自己",
  
  ["emo__jisi"] = "集思",
  [":emo__jisi"] = "每当一张牌不因使用或打出而进入弃牌堆后，若此牌的花色未被“集思”记录，你记录此花色。每当你受到伤害后，你可以摸“集思”记录的花色各一张牌，然后清空记录。",
  ["@emo__jisi_Record"] = "集思",
}

local moe__qinglan = General(extension, "moe__qinglan", "moe", 3, 3, General.Female)

Fk:addPoxiMethod{
  name = "emo__zhuohua_poxi",
  card_filter = function(to_select, selected)
    if #selected < 2 then return true end
    return (Fk:getCardById(selected[1]).suit == Fk:getCardById(selected[2]).suit) == 
    (table.find(selected, function(id) return Fk:getCardById(id).suit == Fk:getCardById(to_select).suit end) ~= nil)
  end,
  feasible = function(selected, data)
    return #selected > 0
  end,
  default_choice = function(data)
    local cards = data[1][2]
    return table.filter(cards, function(id) return Fk:getCardById(id).suit == Fk:getCardById(cards[1]).suit end)
  end,
  prompt = function ()
    return Fk:translate("#emo-zhuohua-get")
  end,
}
local emo__zhuohua = fk.CreateActiveSkill{
  name = "emo__zhuohua",
  anim_type = "drawcard",
  prompt = "#emo__zhuohua-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local ids = room:getNCards(4)
    local to_get = room:askForPoxi(player, "emo__zhuohua_poxi", {{ self.name, ids }}, nil, false)
    
    if #to_get > 0 then
      local choices = {"emo__zhuohua_cishu", "emo__zhuohua_juli"}
      local choice = choices[2]
      if #to_get == 1 then
        choice = room:askForChoice(player, choices, self.name, "#emo__zhuohua-choice")
      elseif Fk:getCardById(to_get[1]).suit == Fk:getCardById(to_get[2]).suit then
        choice = choices[1]
      end
      room:setPlayerMark(player, "@@"..choice.."-turn", 1)
    end

    if #to_get > 0 then
      room:moveCardTo(to_get, Player.Hand, player, fk.ReasonPrey, self.name)
    end
    local throw = table.filter(to_get, function(id) return not table.contains(to_get, id) end)
    if #throw > 0 then
      room:moveCards({
        ids = throw,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = self.name,
        proposer = player.id,
      })
    end
  end,
}

local emo__zhuohua_targetmod = fk.CreateTargetModSkill{
  name = "#emo__zhuohua_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return card and player:getMark("@@emo__zhuohua_cishu-turn") > 0
  end,
  bypass_distances = function(self, player, skill, card)
    return card and player:getMark("@@emo__zhuohua_juli-turn") > 0
  end,
}
emo__zhuohua:addRelatedSkill(emo__zhuohua_targetmod)

moe__qinglan:addSkill(emo__zhuohua)

local emo__zhemu = fk.CreateTriggerSkill{
  name = "emo__zhemu",
  anim_type = "masochism",
  events = { fk.Damaged, fk.AfterCardsMove },
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damaged then 
      return target == player and player:hasSkill(self) and data.from and data.from ~= player and (not data.from.dead) and not data.from:isNude()
    elseif player:hasSkill(self) then
      local n = 0
      for _, move in ipairs(data) do
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if info.fromArea == Card.DrawPile and card:getMark(self.name) > 0 then
            player.room:setCardMark(card, self.name, 0)
            n = n + 1
          end
        end
      end
      if n > 0 then
        self.cost_data = n
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      return room:askForSkillInvoke(player, self.name, nil, "#emo__zhemu-invoke:"..data.from.id)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local from = data.from
      if from:isNude() or from.dead or player.dead then return false end
      local num = math.min(2, #from:getCardIds("he")) 
      local cards = room:askForCardsChosen(player, from, num, num, "he", self.name)
      for _, id in ipairs(cards) do
        room:setCardMark(Fk:getCardById(id), self.name, 1)
      end
      room:moveCards({
        ids = cards,
        from = from.id,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = self.name,
        drawPilePosition = math.random(1, #room.draw_pile),
      })
    else
      local n = self.cost_data
      for _ = 1, n do
        if player.dead then break end 
        if player:isWounded() then
          room:recover { num = 1, skillName = self.name, who = player ,recoverBy = player}
        else
          room:changeShield(player, 1)
        end
      end
    end
  end
}
moe__qinglan:addSkill(emo__zhemu)

local emo__qingyu = fk.CreateTriggerSkill{
  name = "emo__qingyu",
  events = { fk.GameStart },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cid
    for _, id in ipairs(room.void) do
      if Fk:getCardById(id).name == "rain_umbrella" then cid = id break end
    end
    if not cid then return false end
    local partner = table.find(room.alive_players, function (p)
      return Fk.generals[p.general].name == "moe__danyu" or (p.deputyGeneral ~= "" and Fk.generals[p.deputyGeneral].name == "moe__danyu")
    end)
    if partner then
      if U.canMoveCardIntoEquip(player, cid) then
        room:moveCardIntoEquip(player, cid, self.name)
      end
    else
      table.removeOne(room.void, cid)
      table.insert(room.draw_pile, math.random(1, #room.draw_pile), cid)
      room:setCardArea(cid, Card.DrawPile, nil)
      room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
    end
  end
}
moe__qinglan:addSkill(emo__qingyu)


Fk:loadTranslationTable{
  ["moe__qinglan"] = "晴蓝",

  ["emo__zhuohua"] = "濯华",
  [":emo__zhuohua"] = "出牌阶段限一次，你可以观看牌堆顶四张牌并选一项：<br>"..
  "①获得其中一种花色的牌，本回合你使用的牌没有次数限制；<br>"..
  "②获得其中不同花色的牌，本回合你使用牌没有距离限制。<br>"..
  "然后将剩余的牌置入弃牌堆。",

  ["#emo__zhuohua-prompt"] = "濯华:观看牌堆顶四张牌，获得其中花色相同或不同的牌",
  ["emo__zhuohua_poxi"] = "濯华",
  ["emo__zhuohua_cishu"] = "无次数限制",
  ["emo__zhuohua_juli"] = "无距离限制",
  ["#emo-zhuohua-get"] = "濯华：选择要获得的牌",
  ["#emo__zhuohua-choice"] = "濯华：获得你本回合获得的效果",
  ["@@emo__zhuohua_cishu-turn"] = "濯华:次数",
  ["@@emo__zhuohua_juli-turn"] = "濯华:距离",

  ["emo__zhemu"] = "折木",
  [":emo__zhemu"] = "每当你受到其他角色造成的伤害后，你可以将该角色的两张牌洗入牌堆。当一张以此法洗入牌堆的牌下一次离开牌堆时，你回复1点体力（若未受伤改为获得1点护甲）。",
  ["#emo__zhemu-invoke"] = "折木：将 %src 的两张牌洗入摸牌堆",

  ["emo__qingyu"] = "晴雨",
  [":emo__qingyu"] = "锁定技，游戏开始时，将【雨伞】洗入牌堆，若丹雨在场，改为将【雨伞】置于你装备区。",
}

local moe__danyu = General(extension, "moe__danyu", "moe", 3, 3, General.Female)

local emo__muyan = fk.CreateActiveSkill{
  name = "emo__muyan",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
  end,
  card_num = 0,
  card_filter = function() return false end,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:drawCards(1, self.name)
    if player:isKongcheng() then return end
    local ids = room:askForCard(player, 1, 1, false, self.name, false, ".", "#emo__muyan-show")
    player:showCards(ids)
    if player.dead then return end
    local choice = room:askForChoice(player, {"emo__muyan_same", "emo__muyan_different"}, self.name) 
    local card = Fk:getCardById(ids[1])
    local cards = {}
    local cardtype = card:getTypeString()
    if choice == "emo__muyan_same" then
      cards = room:getCardsFromPileByRule(".|.|.|.|.|"..cardtype, 2)
    else
      cards = room:getCardsFromPileByRule(".|.|.|.|.|^"..cardtype, 2)
    end
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonDraw,
        proposer = player.id,
        skillName = self.name,
      })
    end
    if player:getMark("emo__muyan_times") > 0 then
      room:setPlayerMark(player, "emo__muyan_times", 0)
      player:addSkillUseHistory(self.name, -1)
    end
  end,
}
moe__danyu:addSkill(emo__muyan)

local emo__rongxin = fk.CreateTriggerSkill{
  name = "emo__rongxin",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and data.from ~= player and not data.from:isNude() and not data.from.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, nil, "#emo__rongxin-invoke:"..data.from.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    local id = table.random(from:getCardIds("he"))
    room:obtainCard(player, id, false, fk.ReasonPrey)
    if Fk:getCardById(id).suit == Card.Heart and not from.dead then
      room:damage { from = player, to = from, damage = 1, skillName = self.name, damageType = fk.FireDamage, }
    end
    if Fk:getCardById(id).suit == Card.Spade then
      room:addPlayerMark(player, "emo__muyan_times")
    end
  end
}

moe__danyu:addSkill(emo__rongxin)

local emo__yuqing = fk.CreateTriggerSkill{
  name = "emo__yuqing",
  events = { fk.GameStart },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cid
    for _, id in ipairs(room.void) do
      if Fk:getCardById(id).name == "sun_parasol" then cid = id break end
    end
    if not cid then return false end
    local partner = table.find(room.alive_players, function (p)
      return Fk.generals[p.general].name == "moe__qinglan" or (p.deputyGeneral ~= "" and Fk.generals[p.deputyGeneral].name == "moe__qinglan")
    end)
    if partner then
      if U.canMoveCardIntoEquip(player, cid) then
        room:moveCardIntoEquip(player, cid, self.name)
      end
    else
      table.removeOne(room.void, cid)
      table.insert(room.draw_pile, math.random(1, #room.draw_pile), cid)
      room:setCardArea(cid, Card.DrawPile, nil)
      room:doBroadcastNotify("UpdateDrawPile", #room.draw_pile)
    end
  end
}

moe__danyu:addSkill(emo__yuqing)

Fk:loadTranslationTable{
  ["moe__danyu"] = "丹雨",

  ["emo__muyan"] = "沐焰",
  [":emo__muyan"] = "出牌阶段限一次，你可以摸一张牌并展示一张手牌，然后选一项：①摸与之类型相同的两张牌；②摸与之不同类型的两张牌。",
  ["#emo__muyan-show"] = "沐焰：展示一张手牌",
  ["emo__muyan_same"] = "摸与之类型相同的两张牌",
  ["emo__muyan_different"] = "摸与之不同类型的两张牌",

  ["emo__rongxin"] = "融心",
  [":emo__rongxin"] = "每当你受到其他角色造成的伤害后，你可以随机获得该角色一张牌，若为红桃牌，你对其造成1点火焰伤害，若为黑桃牌，你下次发动〖沐焰〗不计入次数限制。",
  ["#emo__rongxin-invoke"] = "是否对 %src 发动“融心”",

  ["emo__yuqing"] = "雨晴",
  [":emo__yuqing"] = "锁定技，游戏开始时，将【晴伞】洗入牌堆，若晴蓝在场，改为将【晴伞】置于你装备区。",
}

local moe__mkmy = General(extension, "moe__mkmy", "moe", 3, 3, General.Female)

local emo__moyao = fk.CreateViewAsSkill{
  name = "emo__moyao",
  anim_type = "switch",
  switch_skill_name = "emo__moyao",
  pattern = "analeptic,peach",
  prompt = function (self)
    return "#emo__moyao-prompt_"..Self:getSwitchSkillState(self.name, false, true)
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).suit == 
    (Self:getSwitchSkillState(self.name) == fk.SwitchYin and Card.Heart or Card.Spade)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c
    if Fk:getCardById(cards[1]).suit == Card.Heart and Self:getSwitchSkillState(self.name) == fk.SwitchYin then
      c = Fk:cloneCard("peach")
    elseif Fk:getCardById(cards[1]).suit == Card.Spade and Self:getSwitchSkillState(self.name) == fk.SwitchYang then
      c = Fk:cloneCard("analeptic")
    else
      return nil
    end
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    if not response then
      local pat = player:getSwitchSkillState(self.name) == fk.SwitchYang and "analeptic" or "peach"
      return Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):matchExp(pat)
    end
  end,
}
local emo__moyao_trigger = fk.CreateTriggerSkill{
  name = "#emo__moyao_trigger",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("emo__moyao") and table.contains(data.card.skillNames, "emo__moyao")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getCardsFromPileByRule(data.card.trueName == "analeptic" and "slash" or "jink")
    if #cards > 0 then
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player.id, "emo__moyao", "@@emo__moyao-inhand")
    end
  end,
}
emo__moyao:addRelatedSkill(emo__moyao_trigger)

moe__mkmy:addSkill(emo__moyao)

local emo__zhilian = fk.CreateActiveSkill{
  name = "emo__zhilian",
  anim_type = "control",
  prompt = "#emo__zhilian-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_num = 0,
  min_card_num = 1,
  card_filter = function(self, to_select, selected)
    return not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    local n = 0
    for _, id in ipairs(effect.cards) do
      if Fk:getCardById(id).type ~= Card.TypeBasic then
        n = n + 1
      end
    end
    if n > 0 then 
      player:drawCards(n, self.name)
      if player.dead then return end
    end
    n = n + #effect.cards
    local list = {"slash","jink","analeptic","peach","slashZLeffect","jinkZLeffect","analepticZLeffect","peachZLeffect"}
    local mark = player:getTableMark("@$emo__zhilian")
    local names = table.filter(list, function(s) return not table.contains(mark, s) end)
    if #names == 0 then return end
    table.insertTable(mark, table.random(names, n))
    room:setPlayerMark(player, "@$emo__zhilian", #mark > 0 and mark or 0)
  end
}

local emo__zhilian_effect = fk.CreateTriggerSkill{
  name = "#emo__zhilian_effect",
  events = {fk.CardUsing, fk.CardResponding, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target ~= player then return false end
    if not (table.contains(data.card.skillNames, "emo__moyao") or (data.extra_data or {}).emo__zhilian_check) then return end
    local mark = type(player:getMark("@$emo__zhilian")) == "table" and player:getMark("@$emo__zhilian") or {}
    if event == fk.TargetSpecified then 
      return data.card.trueName == "slash" and table.contains(mark, "slashZLeffect")
    else
      if table.contains(mark, data.card.trueName) then return true end
      if event == fk.CardResponding then
        return data.card.trueName == "jink" and table.contains(mark, "jinkZLeffect")
      else
        return table.contains(mark, data.card.trueName.."ZLeffect")
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then 
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      data.fixedResponseTimes["jink"] = (data.fixedResponseTimes["jink"] or 1) + 1
      return false
    end 
    local mark = type(player:getMark("@$emo__zhilian")) == "table" and player:getMark("@$emo__zhilian") or {}
    if table.contains(mark, data.card.trueName) then 
      player:drawCards(1, "emo__zhilian")
    end
    if data.card.trueName == "jink" and table.contains(mark,"jinkZLeffect") then
      if not player.dead and data.responseToEvent then
        local to = room:getPlayerById(data.responseToEvent.from)
        if to and not to:isNude() then
          local cid = room:askForCardChosen(player, to, "he", self.name)
          room:obtainCard(player, cid, false, fk.ReasonPrey)
        end
      end
    end
    if event == fk.CardResponding then return end
    if data.card.trueName == "analeptic" and table.contains(mark, "analepticZLeffect") then
      data.extra_data = data.extra_data or {}
      data.extra_data.additionalDrank = (data.extra_data.additionalDrank or 0) + 1
    elseif data.card.trueName == "peach" and table.contains(mark, "peachZLeffect") then
      data.additionalRecover = (data.additionalRecover or 0) + 1
    end
  end,

  refresh_events = {fk.PreCardUse, fk.PreCardRespond},
  can_refresh = function(self, event, target, player, data)
    if target == player and data.card:getMark("@@emo__moyao-inhand") > 0 then
      local cards = data.card.subcards
      -- 排除转化牌，确定此牌与实体牌牌名相同，火扇子可生效，锁视（龙怒）不生效
      return #cards == 0 or (#cards == 1 and Fk:getCardById(cards[1]).trueName == data.card.trueName)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.emo__zhilian_check = true
  end,
}
emo__zhilian:addRelatedSkill(emo__zhilian_effect)
moe__mkmy:addSkill(emo__zhilian)

Fk:loadTranslationTable{
  ["moe__mkmy"] = "美空美音",

  ["emo__moyao"] = "魔药",
  [":emo__moyao"] = "转换技：阳：你可以将一张♠牌当【酒】使用，结算完毕后摸一张【杀】；阴：你可以将一张<font color='red'>♥</font>牌当【桃】使用，结算完毕后摸一张【闪】。",
  ["@@emo__moyao-inhand"] = "魔药",
  ["#emo__moyao_trigger"] = "魔药",
  ["#emo__moyao-prompt_yang"] = "魔药:你可以将一张♠牌当【酒】使用，并摸一张【杀】",
  ["#emo__moyao-prompt_yin"] = "魔药:你可以将一张<font color='red'>♥</font>牌当【桃】使用，并摸一张【闪】",

  ["emo__zhilian"] = "炙炼",
  [":emo__zhilian"] = "出牌阶段限一次，你可以弃置至少一张牌，随机升级等量次数“魔药”中基本牌的效果（弃置一张非基本牌时额外升级一次并摸一张牌）：<br>①—④【酒】/【杀】/【桃】/【闪】使用或打出时摸一张牌；<br>⑤【酒】受影响的【杀】造成伤害+1；<br>⑥【桃】回复值+1；<br>⑦【杀】抵消需要的【闪】+1；<br>⑧【闪】获得响应角色一张牌。",
  ["@$emo__zhilian"] = "炙炼",
  ["#emo__zhilian_effect"] = "炙炼",
  ["#emo__zhilian-prompt"] = "炙炼：你可以弃置任意张牌，升级“魔药”！若弃置非基本牌，则摸等量张牌",
}


local moe__cedrela = General(extension, "moe__cedrela", "moe", 3, 3, General.Female)

local emo__zhongshuo = fk.CreateTriggerSkill{
  name = "emo__zhongshuo",
  events = {fk.EventPhaseEnd},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    local p = table.filter(player.room:getAlivePlayers(), function(p) return not p:isKongcheng() end) -- 确保至少有一人有手牌
    return player:hasSkill(self) and target == player and player.phase == Player.Play and #p > 0
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#emo__zhongshuo-target", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    for _, pl in ipairs(room:getOtherPlayers(to)) do
      if to.dead then break end
      if not pl:isKongcheng() then
        local card = room:askForDiscard(pl, 1, 1, false, self.name, true, ".", "#emo__zhongshuo-use:"..to.id, true)
        if #card > 0 then
          local color = Fk:getCardById(card[1]).color
          room:throwCard(card, self.name, pl, pl)
          room:doIndicate(pl.id, {to.id})
          if color == Card.Red and to:isWounded() then
            room:recover({ who = to,  num = 1, recoverBy = pl, skillName = self.name }) 
          elseif color == Card.Black then
            room:damage { from = pl, to = to, damage = 1, skillName = self.name }
          end
        end
      end
    end
  end,
}
moe__cedrela:addSkill(emo__zhongshuo)

local emo__huocai = fk.CreateTriggerSkill{
  name = "emo__huocai",
  events = {fk.EventPhaseStart},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local lose_p = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move and move.from and move.from ~= move.to then
          for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insertIfNeed(lose_p, move.from)
              break
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if #lose_p > 0 then
      room:sortPlayersByAction(lose_p)
      self.cost_data = lose_p
      return room:askForSkillInvoke(player, self.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(self.cost_data, Util.Id2PlayerMapper)
    room:doIndicate(player.id, self.cost_data)
    local discard_data = {}
    for _, p in ipairs(targets) do
      if not p.dead then
        if room:askForChoice(p, {"emo__huocai_draw:"..player.id, "emo__huocai_discard"} , self.name) == "emo__huocai_discard" then
          local n = #room:askForDiscard(p, 0, 999, true, self.name, true, ".", "#emo__huocai_discard")
          room:setPlayerMark(p, "@emo__huocai", tostring(n))
          table.insert(discard_data, {p, n})
        else
          player:drawCards(1, self.name)
        end
      end
    end
    if #discard_data == 0 then return end
    local min_num = 9999
    for _, dat in ipairs(discard_data) do
      min_num = math.min(min_num, dat[2])
      room:setPlayerMark(dat[1], "@emo__huocai", 0)
    end
    for _, dat in ipairs(discard_data) do
      local p = dat[1]
      if not p.dead and dat[2] == min_num then
        room:delay(300)
        room:doIndicate(player.id, {p.id})
        room:damage{ from = player, to = p, damage = 1, skillName = self.name , damageType = fk.FireDamage }
      end
    end
  end,
}
moe__cedrela:addSkill(emo__huocai)

Fk:loadTranslationTable{
  ["moe__cedrela"] = "塞瑞拉",

  [":emo__zhongshuo"] = "出牌阶段结束时，你可以选择一名角色，除其以外所有角色依次可以弃置一张手牌，若弃置了黑色牌，其对你选择的角色造成1点伤害，若弃置了红色牌，其令你选择的角色回复1点体力。",
  ["emo__zhongshuo"] = "众铄",
  ["#emo__zhongshuo-target"] = "你可对一名角色发动“众铄”",
  ["#emo__zhongshuo-use"] = "弃置一张黑色手牌对 %src 造成1点伤害，或弃置一张红色手牌令 %src 回复1点体力",

  ["emo__huocai"] = "祸财",
  [":emo__huocai"] = "结束阶段开始时，你可以令本回合失去过牌的角色依次选一项：1.令你摸一张牌；2.弃置任意张牌。选择完成后，你对选择2的角色中弃置牌最少的角色依次造成1点火焰伤害。",

  ["@emo__huocai"] = "祸财弃置",
  ["emo__huocai_draw"] = "令 %src 摸一张牌",
  ["emo__huocai_discard"] = "弃置任意张牌(可不弃)",
  ["#emo__huocai_discard"] = "祸财：请弃置任意张牌，弃置最少的角色受到1点火焰伤害",
}

local moe__cheon = General(extension, "moe__cheon", "moe", 4, 4, General.Female)

local emo__fengzun = fk.CreateTriggerSkill{
  name = "emo__fengzun",
  anim_type = "drawcard",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to ~= player.id
    and (data.card.suit == Card.Spade or (data.card.color == Card.Black and data.card.type == Card.TypeTrick))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__fengzun-invoke:"..data.to)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    local to = room:getPlayerById(data.to)
    if not to.chained and not to.dead then
      to:setChainState(true)
    end
  end,
}
moe__cheon:addSkill(emo__fengzun)

local emo__shexin = fk.CreateTriggerSkill{
  name = "emo__shexin",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.PreDamage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.to == player then return true end
    local transfer = data.to.chained and data.damageType ~= fk.NormalDamage
    room:loseHp(data.to, data.damage, self.name)
    if transfer then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if p ~= data.to and p.chained and not p.dead then
          room:loseHp(p, data.damage, self.name)
        end
      end
    end
    return true
  end,
}
moe__cheon:addSkill(emo__shexin)

Fk:loadTranslationTable{
  ["moe__cheon"] = "琴",
  ["emo__fengzun"] = "奉尊",
  [":emo__fengzun"] = "每当你使用♠牌或黑色锦囊牌指定一名其他角色为目标后，你可以摸一张牌并横置该角色。",
  ["#emo__fengzun-invoke"] = "奉尊：你可以摸一张黑色牌，并横置 %src",

  ["emo__shexin"] = "蛇心",
  [":emo__shexin"] = "锁定技，防止你对自己造成伤害。你对其他角色造成的伤害改为令其流失等量的体力，若是属性伤害且其已横置，令除其外所有横置的其他角色依次失去等量体力。",
}

local moe__swansister = General(extension, "moe__swansister", "moe", 3, 4, General.Female)

local emo__qingche = fk.CreateActiveSkill{
  name = "emo__qingche",
  anim_type = "control",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  interaction = function()
    local all_choices = {"#emo__qingche_other", "#emo__qingche_draw"}
    local choices = {all_choices[1]}
    if Self:getHandcardNum() < Self.maxHp then
      table.insert(choices, all_choices[2])
    end
    return UI.ComboBox { choices = choices, all_choices = all_choices}
  end,
  target_filter = function(self, to_select, selected)
    if self.interaction.data == "#emo__qingche_other" then
      local to = Fk:currentRoom():getPlayerById(to_select)
      return #selected == 0 and to_select ~= Self.id and to:getHandcardNum() ~= to.hp
    end
  end,
  feasible = function(self, selected)
    if self.interaction.data == "#emo__qingche_other" then
      return #selected == 1
    else
      return Self:getHandcardNum() < Self.maxHp
    end
  end,
  on_use = function(self, room, use)
    local player = room:getPlayerById(use.from)
    if #use.tos > 0 then
      local to = room:getPlayerById(use.tos[1])
      local x = to:getHandcardNum() - to.hp
      if x > 0 then
        room:askForDiscard(to, x, x, false, self.name, false)
      elseif x < 0 then
        to:drawCards(-x, self.name)
      end
    else
      local y = player.maxHp - player:getHandcardNum()
      if y > 0 then
        player:drawCards(y, self.name)
      end
    end
  end,
}
moe__swansister:addSkill(emo__qingche)

local emo__jiaoyi = fk.CreateTriggerSkill{
  name = "emo__jiaoyi",
  events = {fk.RoundStart},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
    for _, p in ipairs(room:getAlivePlayers()) do
      if not p.dead then
        p:drawCards(1, self.name)
      end
    end
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p.dead then
        if p:isNude() or #room:askForDiscard(p, 1, 1, true, self.name, true, ".|.|spade,club", "#emo__jiaoyi-discard:"..player.id)==0 then
          local mark = p:getTableMark("@@emo__jiaoyi-round")
          table.insertIfNeed(mark, player.id)
          room:setPlayerMark(p, "@@emo__jiaoyi-round", mark)
        end
      end
    end
  end,
}
local emo__jiaoyi_prohibit = fk.CreateProhibitSkill{
  name = "#emo__jiaoyi_prohibit",
  is_prohibited = function(self, from, to, card)
    return card and card.color == Card.Black and from and table.contains(from:getTableMark("@@emo__jiaoyi-round"), to.id)
  end,
}
emo__jiaoyi:addRelatedSkill(emo__jiaoyi_prohibit)
moe__swansister:addSkill(emo__jiaoyi)


Fk:loadTranslationTable{
  ["moe__swansister"] = "天鹅双子",

  ["emo__qingche"] = "擎掣",
  [":emo__qingche"] = "出牌阶段限两次。你可以选一项：<br>1.令一名其他角色将手牌数调整至其体力值。<br>2.将你的手牌摸至体力上限。",
  ["#emo__qingche_other"] = "令其他角色将手牌调整至体力值",
  ["#emo__qingche_draw"] = "将你的手牌摸至体力上限",

  ["emo__jiaoyi"] = "交谊",
  [":emo__jiaoyi"] = "每轮开始时，你可以令每名角色各摸一张牌，然后令其他角色依次选一项：1.弃置一张黑色牌，2.本轮其使用的黑色牌无法指定你为目标。",
  ["#emo__jiaoyi-discard"] = "交谊：弃置一张黑色牌，否则本轮无法对 %src 使用黑色牌",
  ["#emo__jiaoyi_prohibit"] = "交谊",
  ["@@emo__jiaoyi-round"] = "交谊",
}

local moe__guye = General(extension, "moe__guye", "moe", 4, 4, General.Female)

local emo__lingyin = fk.CreateViewAsSkill{
  name = "emo__lingyin",
  pattern = ".|.|.|.|.|basic",
  interaction = function()
    local names = {}
    local mark = Self:getMark("@$emo__lingyin-turn")
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeBasic and not card.is_derived and
        ((Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
        if mark == 0 or (not table.contains(mark, card.trueName)) then
          table.insertIfNeed(names, card.name)
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected < 2
  end,
  view_as = function(self, cards)
    if (#cards ~= 0 and #cards ~= 2) or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:addPlayerMark(player, "emo__lingyin_invoked-turn", 1)
    if #use.card.subcards == 0 then
      room:loseHp(player, 1, self.name)
    end
    local mark = player:getTableMark("@$emo__lingyin-turn")
    table.insertIfNeed(mark, use.card.trueName)
    room:setPlayerMark(player, "@$emo__lingyin-turn", mark)
  end,
  enabled_at_play = function(self, player)
    return not player.dying
  end,
  enabled_at_response = function(self, player)
    return not player.dying
  end,
}

local emo__lingyin_trigger = fk.CreateTriggerSkill{
  name = "#emo__lingyin_trigger",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("emo__lingyin") and player:getMark("emo__lingyin_invoked-turn") > 0 and table.find(player.room.alive_players , function(p) return p.hp == 1 end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"#emo__lingyin_losehp", "#emo__lingyin_recover","cancel"}, "emo__lingyin", "#emo__lingyin-ask")
    if choice ~= "cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = self.cost_data
    for _, p in ipairs(room:getAlivePlayers()) do
      if p.hp == 1 then
        if choice == "#emo__lingyin_losehp" then
          room:loseHp(p, 1, self.name)
        else
          room:recover({ who = p,  num = 1, recoverBy = player, skillName = self.name }) 
        end
      end
    end
  end,
}
emo__lingyin:addRelatedSkill(emo__lingyin_trigger)

moe__guye:addSkill(emo__lingyin)

local emo__yuxiang = fk.CreateTriggerSkill{
  name = "emo__yuxiang",
  mute = true, 
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card:isVirtual() and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = #data.card.subcards
    local prompt = "#emo__yuxiang-invoke1::"..target.id
    if n ~= 1 then prompt = "#emo__yuxiang-invoke::"..target.id..":"..n end
    return room:askForSkillInvoke(player, self.name, nil, prompt)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = target
    local n = #data.card.subcards
    local choice = "#emo__yuxiang-draw"
    if n ~= 1 then
      choice = room:askForChoice(player, {"#emo__yuxiang-draw:::" .. n,  "#emo__yuxiang-discard:::" .. n}, self.name)
    end
    if choice:startsWith("#emo__yuxiang-draw") then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "support")
      to:drawCards(n, self.name)
      room:askForDiscard(to, 1, 1, true, self.name, false)
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "control")
      to:drawCards(1, self.name)
      if n > 0 then
        room:askForDiscard(to, n, n, true, self.name, false)
      end
    end
  end,
}
moe__guye:addSkill(emo__yuxiang)

Fk:loadTranslationTable{
  ["moe__guye"] = "孤夜",

  ["emo__lingyin"] = "泠音",
  [":emo__lingyin"] = "每回合每种牌名限一次；当你需要使用或打出基本牌时，若你不处于濒死状态，你可选择一项视为之：<br>①：将两张牌视为此牌；<br>②：失去1点体力；<br>回合结束时，若你本回合发动过〖泠音〗，你可以令体力值为1的所有角色失去或回复1点体力。",
  ["#emo__lingyin_trigger"] = "泠音",
  ["@$emo__lingyin-turn"] = "泠音",
  ["#emo__lingyin_recover"] = "回复体力",
  ["#emo__lingyin_losehp"] = "失去体力",
  ["#emo__lingyin-ask"] = "选择“泠音”的效果",
  ["cancel"] = "取消",

  ["emo__yuxiang"] = "余响",
  [":emo__yuxiang"] = "当一名角色使用非实体牌后，你可以令其执行一项：<br>①：摸1张牌并弃X张牌；<br>②：摸X张牌并弃1张牌；<br>(X为该非实体牌所含的子牌数)",
  ["#emo__yuxiang-invoke"] = "余响：可令 %dest 1.摸一张牌再弃%arg张牌2.摸%arg张牌再弃一张牌",
  ["#emo__yuxiang-invoke1"] = "余响：可令 %dest 摸一张牌再弃一张牌",
  ["@@emo__yuxiang_target-turn"] = "余响",
  ["#emo__yuxiang-draw"] = "摸%arg张牌，弃置1张牌",
  ["#emo__yuxiang-discard"] = "摸1张牌，弃置%arg张牌",
}

local moe__migu = General(extension, "moe__migu", "moe", 4, 4, General.Female)

local emo__zhilei = fk.CreateActiveSkill{
  name = "emo__zhilei",
  anim_type = "offensive",
  card_num = 1,
  target_num = 1,
  prompt = "#emo__zhilei-prompt",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected == 0 and #selected_cards > 0 then
      local target = Fk:currentRoom():getPlayerById(to_select)
      local card = Fk:cloneCard("timebomb")
      if not card then return false end
      card:addSubcard(selected_cards[1])
      return (target:hasDelayedTrick("timebomb") or (not Self:isProhibited(target, card)))
      and target:getMark("emo__zhilei_target-phase") == 0
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(target, "emo__zhilei_target-phase", 1)
    local draw = Fk:getCardById(effect.cards[1]).type == Card.TypeEquip
    if target:hasDelayedTrick("timebomb") then -- 引爆
      room:throwCard(effect.cards, self.name, player, player)
      for _, id in ipairs(target.player_cards[Player.Judge]) do
        local card = target:getVirualEquip(id) -- 判断是否是虚拟装备（锦囊）
        local isVirtual
        if card then isVirtual = true else card = Fk:getCardById(id) end
        if card.name == "timebomb" then
          room:damage { from = nil, to = target, damage = 2, card = card, skillName = "timebomb_skill",
          damageType = (math.random(1,2)==1 and fk.FireDamage or fk.ThunderDamage) }
          if isVirtual then player:removeVirtualEquip(id) end
          room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonUse, self.name)
        end
      end
    else
      room:useVirtualCard("timebomb", effect.cards, player, target, self.name)
    end
    if not player.dead and draw then
      player:drawCards(1, self.name)
    end
  end,
}

moe__migu:addSkill(emo__zhilei)

local emo__xiaohuo = fk.CreateTriggerSkill{
  name = "emo__xiaohuo",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return player:hasSkill(self) and data.damageType ~= fk.NormalDamage and target == player
    else
      return player:hasSkill(self) and data.damageType ~= fk.NormalDamage 
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      data.damage = data.damage + 1
    else
      player:drawCards(data.damage, self.name)
    end
  end,
}

moe__migu:addSkill(emo__xiaohuo)

Fk:loadTranslationTable{
  ["moe__migu"] = "米咕",
  ["#moe__migu"] = "阴暗炸弹迷",
  
  ["emo__zhilei"] = "制雷",
  [":emo__zhilei"] = "出牌阶段对每名角色限一次，你可以选一项：1.将一张黑色牌当【定时炸弹】对其使用；2.弃置一张黑色牌，引爆其判定区内的【定时炸弹】。然后若你因此使用或弃置的牌为装备牌，你摸一张牌。",
  ["#emo__zhilei-prompt"] = "制雷：每角色限一次，你可将一张黑色牌当【定时炸弹】使用，若其已有炸弹，引爆之！",

  ["emo__xiaohuo"] = "硝火",
  [":emo__xiaohuo"] = "锁定技，你受到的属性伤害+1。每当一名角色受到属性伤害后，你摸等于伤害值张牌。",
}

local moe__yifu = General(extension, "moe__yifu", "moe", 4, 4, General.Female)

local emo__exin = fk.CreateTriggerSkill{
  name = "emo__exin",
  anim_type = "drawcard",
  events = {fk.Damaged, fk.EventPhaseEnd, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player == target then
      if event == fk.EventPhaseEnd then
        return player.phase == Player.Discard and player:getMark("@emo__exin") > 0
      else
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseEnd then
      local n = 0
      room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        local move = e.data[1]
        if move and move.from and move.from == player.id and move.moveReason == fk.ReasonDiscard and move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
           if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              n = n + 1
            end
          end
        end return false
      end, Player.HistoryPhase)
      if n > 0 then
        self.cost_data = n
        return true
      end
    else
      return room:askForSkillInvoke(player, self.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseEnd then
      local n = self.cost_data
      local num = math.min(n, player:getMark("@emo__exin"))
      room:removePlayerMark(player, "@emo__exin", num)
      player:drawCards(num, self.name)
    else
      player:drawCards(1, self.name)
      room:addPlayerMark(player, "@emo__exin")
    end
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@emo__exin", 0)
  end,
}

local emo__exin_maxcards = fk.CreateMaxCardsSkill{
  name = "#emo__exin_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(emo__exin) then
      return - player:getMark("@emo__exin")
    end
  end,
}
emo__exin:addRelatedSkill(emo__exin_maxcards)

moe__yifu:addSkill(emo__exin)

Fk:loadTranslationTable{
  ["moe__yifu"] = "伊芙",
  ["#moe__yifu"] = "恶作剧恶魔",

  ["emo__exin"] = "恶衅",
  [":emo__exin"] = "每当你造成或受到伤害后，你可以摸一张牌并令手牌上限-1。若你因〖恶衅〗减少手牌上限，弃牌阶段结束时，你每弃置一张牌，便恢复1点手牌上限并摸一张牌。",
  ["@emo__exin"] = "恶衅",
}

local moe__baijingchun = General(extension, "moe__baijingchun", "moe", 4, 4, General.Female)

local emo__shifeng = fk.CreateTriggerSkill{
  name = "emo__shifeng",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.phase == Player.Start then
      local cards = table.filter(player.room.draw_pile, function(id)
        local card = Fk:getCardById(id)
        return card.type == Card.TypeEquip and #player:getAvailableEquipSlots(card.sub_type) > 0
         and player:canUse(card) and not player:prohibitUse(card)
      end)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local id = room:askForCardChosen(player, player, { card_data = { { self.name, table.random(self.cost_data, 4) }  } }, self.name, "#emo__shifeng-card")
    local card = Fk:getCardById(id)
    room:useCard({
      from = player.id,
      tos = {{player.id}},
      card = card,
    })
    if card.sub_type == Card.SubtypeWeapon then
      U.askForUseVirtualCard(room, player, "slash", nil, self.name, nil, true, true, true, true)
    end
  end,
}
moe__baijingchun:addSkill(emo__shifeng)

local getXiaxingSkills = function (room)
  local skills = room:getTag("emo__xiaxing_skills")
  if skills == nil then
    skills = {{}, {}, {}}
    for _, general_name in ipairs(room.general_pile) do
      local general = Fk.generals[general_name]
      for _, skill_name in ipairs(general:getSkillNameList()) do
        local skill = Fk.skills[skill_name]
        if not (skill.switchSkillName or skill.frequency > 3) then
          local str = Fk:translate(":"..skill.name):gsub("<[^>]+>", "")
          for i = 1, 3 do
            if #str/3 >= (i-1)*30 and #str/3 < i*30 then
              table.insertIfNeed(skills[i], skill_name)
            end
          end
        end
      end
    end
    room:setTag("emo__xiaxing_skills", skills)
  end
  return skills
end

local emo__xiaxing = fk.CreateTriggerSkill{
  name = "emo__xiaxing",
  events = {fk.RoundStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_skills = getXiaxingSkills(room)
    local skills = {}
    for _, all in ipairs(all_skills) do
      local sk = table.filter(all, function (s)
        return not player:hasSkill(s, true) and 
        (#Fk.skills[s].attachedKingdom == 0 or table.contains(Fk.skills[s].attachedKingdom, player.kingdom))
      end)
      if #sk > 0 then
        table.insert(skills, table.random(sk))
      end
    end
    if #skills > 0 then
      local skill = room:askForChoice(player, skills, self.name, "#emo__xiaxing-skill", true)
      local mark = player:getTableMark("emo__xiaxing_record")
      table.insert(mark, skill)
      room:setPlayerMark(player, "emo__xiaxing_record", mark)
      room:handleAddLoseSkills(player, skill, nil, true, false)
    end
  end,
}

local emo__xiaxing_delay = fk.CreateTriggerSkill{
  name = "#emo__xiaxing_delay",
  events = {fk.RoundEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return type(player:getMark("emo__xiaxing_record")) == "table"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = player:getMark("emo__xiaxing_record")
    room:setPlayerMark(player, "emo__xiaxing_record", 0)
    room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"))
  end,
}
emo__xiaxing:addRelatedSkill(emo__xiaxing_delay)

moe__baijingchun:addSkill(emo__xiaxing)

Fk:loadTranslationTable{
  ["moe__baijingchun"] = "白井淳",

  ["emo__shifeng"] = "试锋",
  [":emo__shifeng"] = "准备阶段开始时，你可以从牌堆四张装备牌中选择并使用一张，若此牌为武器牌，你可以视为使用一张【杀】。",
  ["#emo__shifeng-card"] = "试锋：选择并使用其中一张",

  ["emo__xiaxing"] = "侠行",
  [":emo__xiaxing"] = "锁定技，每轮开始时，你从技能描述字数分别为1~30，31~60，61~90的三个技能中选择一个于本轮内获得。",
  ["#emo__xiaxing-skill"] = "侠行：选择一个技能于本轮内获得",
  ["#emo__xiaxing_delay"] = "侠行",
}

-- luoshalin
local moe__rosalyn = General(extension, "moe__rosalyn", "moe", 4, 4, General.Female)

local emo__xuedie = fk.CreateActiveSkill{
  name = "emo__xuedie",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 
    and (#player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot) )
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local choices = player:getAvailableEquipSlots()
    if not table.contains(player.sealedSlots, Player.JudgeSlot) then
      table.insert(choices, Player.JudgeSlot)
    end
    if #choices == 0 then return false end
    local choice = room:askForChoice(player, choices, self.name, "#emo__xuedie-ask")
    room:abortPlayerArea(player, choice)
    if player.dead then return end
    if choice == Player.JudgeSlot then
      room:changeMaxHp(player, 1)
    else
      player:drawCards(2, "emo__xuedie")
    end 
  end,
}

local emo__xuedie_trigger = fk.CreateTriggerSkill{
  name = "#emo__xuedie_trigger",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(emo__xuedie) and (data.card.trueName == "slash" or data.card:isCommonTrick()) then
      return #player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot) 
    end
  end,
  on_use = function(self, event, target, player, data)
    emo__xuedie:onUse(player.room, {
      from = player.id,
      cards = {},
      tos = {},
    })
  end,
}
emo__xuedie:addRelatedSkill(emo__xuedie_trigger)

moe__rosalyn:addSkill(emo__xuedie)

---FIXEME
local emo__dingfan = fk.CreateViewAsSkill{
  name = "emo__dingfan",
  anim_type = "offensive",
  enabled_at_play = function(self, player)
    return player.phase == Player.Play and not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected)
    return #selected < 1 + Self:getMark("@emo__dingfan-phase") and table.contains(Self.player_cards[Player.Hand], to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 + Self:getMark("@emo__dingfan-phase") then return nil end
    local c = Fk:cloneCard(Fk:getCardById(cards[1]).color == Card.Black and "savage_assault" or "archery_attack")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local targets = room:getOtherPlayers(player)
    local list = {}
    local choices = {"savage_assault", "archery_attack"}
    for _, p in ipairs(targets) do
      local _data = json.encode({ choices, choices, self.name, "#emo__dingfan-choice" })
      p.request_data = _data
    end
    room:notifyMoveFocus(targets, self.name)
    room:doBroadcastRequest("AskForChoice", targets)
    for _, p in ipairs(targets) do
      local choice = p.reply_ready and p.client_reply or table.random(choices)
      if choice == use.card.name then
        table.insert(list, p.id)
      end
    end
    use.nullifiedTargets = list
    if #list == #targets then
      room:addPlayerMark(player, "@emo__dingfan-phase", 1)
    end
  end,
}
moe__rosalyn:addSkill(emo__dingfan)

local emo__junwang = fk.CreateTriggerSkill{
  name = "emo__junwang",
  events = {fk.BeforeGameOverJudge},
  frequency = Skill.Limited,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.damage and data.damage.from == player
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    and table.find(player.room.alive_players, function (p) return p.role == "renegade" end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"loyalist", "rebel"}, self.name)
    for _, p in ipairs(room.alive_players) do
      if p.role == "renegade" then
        room:setPlayerProperty(p, "role", choice)
        --room:setPlayerProperty(p, "role_shown", true)
      end
    end
  end,
}
moe__rosalyn:addSkill(emo__junwang)

Fk:loadTranslationTable{
  ["moe__rosalyn"] = "罗莎琳",
  ["#moe__rosalyn"] = "血色宴会",

  ["emo__xuedie"] = "血蝶",
  [":emo__xuedie"] = "出牌阶段限一次，或每当你成为【杀】或普通锦囊牌的目标后，你可以选一项：1.废除一个装备区，摸两张牌；2.废除判定区，增加一点体力上限。",
  ["#emo__xuedie-ask"] = "血蝶：你可以废除一个区域，装备区：摸两张牌，判定区：加体力上限",
  ["#emo__xuedie_trigger"] = "血蝶",

  ["emo__dingfan"] = "定藩",
  [":emo__dingfan"] = "出牌阶段，你可以选择颜色相同的一张手牌，令所有其他角色猜测颜色，然后你将这些牌按颜色转化使用（黑色/红色当【南蛮入侵】/【万箭齐发】），此牌对猜对的角色无效。若所有其他角色均猜对，本阶段内发动此技能需要的牌数+1。",
  ["#emo__dingfan-choice"] = "定藩：选择对你无效的牌名",
  ["@emo__dingfan-phase"] = "定藩",

  ["emo__junwang"] = "君望",
  [":emo__junwang"] = "限定技，你杀死一名角色时，你可以将存活的内奸的身份改为反贼或忠臣。",
  ["#emo__junwang_choose"] = "你须对至少一名其他角色发动“君望”",
  ["#emo__junwang_losehp"] = "令 %src 失去1点体力",
  ["#emo__junwang_drawcard"] = "令 %src 摸两张牌",

  ["$emo__junwang1"] = "我亦可为王",
  ["$emo__junwang2"] = "窃钩者诛，窃国者侯",
}

local moe__wuniang = General(extension, "moe__wuniang", "moe", 3, 4, General.Female)

local emo__zhanwu = fk.CreateViewAsSkill{
  name = "emo__zhanwu",
  anim_type = "offensive",
  pattern = "slash,duel",
  prompt = function()
    return "#emo__zhanwu_mode"..Self:getMark("emo__zhanwu_mode")
  end,
  card_filter = function(self, to_select, selected)
    if #selected > 0 then return false end
    local card = Fk:getCardById(to_select)
    local normal_mode = Self:getMark("emo__zhanwu_mode") == 0
    local c 
    if card.color == Card.Red and ((card.type == Card.TypeBasic) == normal_mode) then
      c = Fk:cloneCard("fire__slash")
    elseif card.color == Card.Black and ((card.type ~= Card.TypeBasic) == normal_mode) then
      c = Fk:cloneCard("duel")
    end
    if not c then return false end
    return (Fk.currentResponsePattern == nil and c.skill:canUse(Self, c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c
    if Fk:getCardById(cards[1]).color == Card.Red then
      c = Fk:cloneCard("fire__slash")
    elseif Fk:getCardById(cards[1]).color == Card.Black then
      c = Fk:cloneCard("duel")
    end
    if c then
      c.skillName = "emo__zhanwu"
      c:addSubcard(cards[1])
      return c
    end
  end,
  before_use = function(self, player, use)
    if use.card.trueName == "slash" then use.extraUse = true end
  end,
  enabled_at_response = function(self, player, response)
    return not response and not player:isNude()
  end,
}
moe__wuniang:addSkill(emo__zhanwu)

local emo__yanzhi_negative = fk.CreateTriggerSkill{
  name = "#emo__yanzhi_negative",
  frequency = Skill.Compulsory,
  events = {fk.EnterDying},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player:usedSkillTimes("emo__yanzhi", Player.HistoryGame) == 0 and player:hasSkill("emo__yanzhi") and player == target
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    room:recover({ who = player, num = player.maxHp-player.hp, recoverBy = player, skillName = "emo__yanzhi" })
    room:handleAddLoseSkills(player, "-emo__yanzhi")
  end,
}

local emo__yanzhi = fk.CreateTriggerSkill{
  name = "emo__yanzhi",
  frequency = Skill.Wake,
  events = {fk.TurnEnd},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:hasSkill(self)
  end,
  can_wake = function(self, event, target, player, data)
    return #player.room.logic:getEventsOfScope(GameEvent.Dying, 1, function(e)
      local dying = e.data[1]
      return dying.who ~= player.id and dying.damage and dying.damage.from == player
    end, Player.HistoryTurn) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    player:drawCards(3, self.name)
    room:handleAddLoseSkills(player, "emo__lianpian")
  end,
}
emo__yanzhi:addRelatedSkill(emo__yanzhi_negative)

moe__wuniang:addSkill(emo__yanzhi)

local emo__lianpian = fk.CreateActiveSkill{
  name = "emo__lianpian",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  prompt = "#emo__lianpian-prompt",
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local get = {}
    for _, pattern in ipairs({"spade,club","heart,diamond"}) do
      local cards = room:getCardsFromPileByRule(".|.|"..pattern)
      if #cards > 0 then
        table.insert(get, cards[1])
      end
    end
    room:moveCardTo(get, Card.PlayerHand, player, fk.ReasonPrey, self.name)
    room:setPlayerMark(player, "emo__zhanwu_mode", player:getMark("emo__zhanwu_mode") == 0 and 1 or 0)
  end,
}
local emo__lianpian_prohibit = fk.CreateProhibitSkill{
  name = "#emo__lianpian_prohibit",
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, to, card)
    return to:hasSkill("emo__lianpian") and (card:isVirtual() or card.name ~= Fk:getCardById(card.id, true).name) and #Card:getIdList(card) > 0
  end,
}
emo__lianpian:addRelatedSkill(emo__lianpian_prohibit)

moe__wuniang:addRelatedSkill(emo__lianpian)

Fk:loadTranslationTable{
  ["moe__wuniang"] = "舞娘",

  ["emo__zhanwu"] = "战舞",
  [":emo__zhanwu"] = "你可以将一张红色基本牌当不计入次数的火【杀】使用。你可以将一张黑色非基本牌当【决斗】使用。",
  ["#emo__zhanwu_mode0"] = "战舞：将红色基本牌当火【杀】，黑色非基本牌当【决斗】使用",
  ["#emo__zhanwu_mode1"] = "战舞：将红色非基本牌当火【杀】，黑色基本牌当【决斗】使用",

  ["emo__yanzhi"] = "燕志",
  ["#emo__yanzhi_negative"] = "燕志",
  [":emo__yanzhi"] = "①觉醒技，任何角色回合结束时，若你本回合造成其他角色进入过濒死状态，你扣减1点体力上限，摸三张牌，获得技能〖连翩〗。②当你进入濒死状态时，若你未觉醒〖燕志〗，你须扣减1点体力上限，将体力回复至体力上限，然后失去〖燕志〗。",

  ["emo__lianpian"] = "连翩",
  [":emo__lianpian"] = "出牌阶段限一次，你可以摸红色和黑色各一张牌，然后切换〖战舞〗描述中的“基本牌”和“非基本牌”。锁定技，你无法成为转化牌的目标。",
  ["#emo__lianpian-prompt"] = "连翩：摸红色和黑色各一张牌，然后修改〖战舞〗",
  ["#emo__lianpian_prohibit"] = "连翩",

  ["$emo__yanzhi1"] = "",
  ["$emo__yanzhi2"] = "",
}

local moe__xiangyan = General(extension, "moe__xiangyan", "moe", 3, 3, General.Female)

local emo__yanjiaos = fk.CreateActiveSkill{
  name = "emo__yanjiaos",
  anim_type = "support",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 3,
  card_filter = function(self, to_select, selected)
    return #selected < 3 and table.contains(Self.player_cards[Player.Hand], to_select)
  end,
  target_num = 1,
  target_filter = function(self, to_select, selected, cards)
    return #selected == 0 and to_select ~= Self.id and #cards == 3
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    player:showCards(effect.cards)
    local Ocards1 = effect.cards
    local Ocards2 = room:getNCards(3)
    local to_get = room:askForCardsChosen(target, player, 3, 3, { card_data = { {player.general, Ocards1},{"Top", Ocards2} } }, self.name, "#emo__yanjiaos-choose:"..player.id)
    local get_fromHand,get_fromTop,to_back = {},{},{} 
    table.insertTable(Ocards1, Ocards2)
    for _,cid in ipairs(to_get) do
      if table.contains(player:getCardIds("h"), cid) then
        table.insert(get_fromHand, cid)
      end
    end
    for _,cid in ipairs(Ocards2) do
      if table.contains(to_get, cid) then
        table.insert(get_fromTop, cid)
      else
        table.insert(to_back, cid)
      end
    end
    local moveInfos = {}
    if #get_fromHand > 0 then -- 其获得你的牌
      table.insert(moveInfos,{
        to = target.id,
        ids = get_fromHand,
        from = player.id,
        toArea = Player.Hand,
        moveReason = fk.ReasonGive,
        proposer = player.id,
        skillName = self.name,
      })
    end
    if #get_fromTop > 0 then -- 其获得牌堆牌
      table.insert(moveInfos, {
        to = target.id,
        ids = get_fromTop,
        toArea = Player.Hand,
        moveReason = fk.ReasonPrey,
        skillName = self.name,
      })
    end
    if #to_back > 0 then
      table.insert(moveInfos, {-- 自己获得
        to = player.id,
        ids = to_back,
        toArea = Player.Hand,
        moveReason = fk.ReasonPrey,
        proposer = player.id,
        skillName = self.name,
      })
    end
    room:moveCards(table.unpack(moveInfos))
    if player.dead then return end
    if #get_fromHand <= 1 then
      room:changeMaxHp(player, 1)
    elseif not player:isNude() then
      -- AI 用这个视为技会报错
      local _, dat = room:askForUseViewAsSkill(player, "emo__yanjiaos_viewas", "#emo__yanjiaos_viewascard", true, {bypass_times = true})
      if dat then
        local card = Fk.skills["emo__yanjiaos_viewas"]:viewAs(dat.cards)
        local mark = player:getTableMark("emo__yanjiaos")
        table.insert(mark, card.name)
        room:setPlayerMark(player, "emo__yanjiaos", mark)
        room:useCard{
          from = player.id,
          tos = table.map(dat.targets, function(p) return {p} end),
          card = card,
          extraUse = true,
        }
      end
    end
  end,
}

local emo__yanjiaos_viewas = fk.CreateViewAsSkill{
  name = "emo__yanjiaos_viewas",
  interaction = function()
    local names, all_names = {}, {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeTrick and not card.is_derived and Self:canUse(card) then
        table.insertIfNeed(all_names, card.name)
        if not table.contains(Self:getTableMark("emo__yanjiaos"), card.name) then
          table.insertIfNeed(names, card.name)
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names, all_choices = all_names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = "emo__yanjiaos"
    return card
  end,
}
Fk:addSkill(emo__yanjiaos_viewas)

moe__xiangyan:addSkill(emo__yanjiaos)

local emo__ximing = fk.CreateTriggerSkill{
  name = "emo__ximing",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and (not target.dead) and not target:isNude()
    and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, nil, "#emo__ximing-invoke:"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(target, 1, 1, true, self.name, false, ".", "#emo__ximing-discard")
    if target.dead then return end
    if #cards > 0 then
      local card = Fk:getCardById(cards[1])
      if card.color == Card.Red and card.type == Card.TypeBasic then
        room:recover { num = 1, skillName = self.name, who = target, recoverBy = player}
      else
        local x = target.maxHp - target:getHandcardNum()
        if x > 0 then 
          target:drawCards(x, self.name) 
        end
      end
    end
  end,
}
moe__xiangyan:addSkill(emo__ximing)

Fk:loadTranslationTable{
  ["moe__xiangyan"] = "湘燕",

  ["emo__yanjiaos"] = "言教",
  [":emo__yanjiaos"] = "出牌阶段限一次，你可以展示三张手牌，令一名其他角色观看牌堆顶三张牌，其在这六张牌中选择三张获得，你获得其余牌。若其获得你的牌数："..
  "<br>①不大于1，你增加1点体力上限。"..
  "<br>②大于1，你可以将一张牌当任意锦囊牌使用（每种牌名限一次）。",

  ["#emo__yanjiaos-choose"] = "言教：选择三张获得，其余牌令 %src 获得",
  ["DrawPile"] = "牌堆",
  ["#emo__yanjiaos-target"] = "言教：可将选择的牌交给一名角色，点“取消”交给自己",
  ["emo__yanjiaos_viewas"] = "言教",
  ["#emo__yanjiaos_viewascard"] = "言教：你可以将一张牌当任意锦囊牌使用",

  ["emo__ximing"] = "惜命",
  [":emo__ximing"] = "每回合一次，每当一名角色受到伤害后，你可以令其弃置一张牌：若弃置了红色基本牌，其回复1点体力；若为其他牌，其将手牌摸至体力上限。",
  ["#emo__ximing-invoke"] = "是否对 %src 发动“惜命”",
  ["#emo__ximing-discard"] = "惜命：请弃置一张牌，若为红色基本牌，回复1点体力，否则你将手牌摸至体力上限",
}

local moe__qianxueji = General(extension, "moe__qianxueji", "moe", 4, 4, General.Female)

local emo__mingdao = fk.CreateTriggerSkill{
  name = "emo__mingdao",
  events = {fk.GameStart , fk.AfterCardsMove},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(self)
    else
      if player:hasSkill(self) and player.phase == Player.Play then
        local x = 0
        for _, move in ipairs(data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              local card = Fk:getCardById(info.cardId)
              if card.type == Card.TypeEquip then
                x = x + 1
              end
            end
          end
        end
        if x > 0 then
          self.cost_data = x
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local cardId = MoeFunc.getDerivedCard(room, "nameless_sword")
      if cardId and room:getCardArea(cardId) == Card.Void then
        table.removeOne(room.void, cardId)
        table.insert(room.draw_pile, math.random(1, #room.draw_pile), cardId)
        room:setCardArea(cardId, Card.DrawPile, nil)
        room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
      end
    else
      player:drawCards(self.cost_data, self.name)
    end
  end,
}

local emo__mingdao_tm = fk.CreateTargetModSkill{
  name = "#emo__mingdao_tm",
  bypass_times = function(self, player, skill, scope)
    if player:hasSkill(self) and skill and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      local weapon = player:getEquipment(Card.SubtypeWeapon)
      return weapon and Fk:getCardById(weapon).name == "nameless_sword"
    end
  end,
}
emo__mingdao:addRelatedSkill(emo__mingdao_tm)

moe__qianxueji:addSkill(emo__mingdao)

local emo__xinzhuang = fk.CreateTriggerSkill{
  name = "emo__xinzhuang",
  events = {fk.CardUseFinished},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.type == Card.TypeEquip 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local times = player:usedSkillTimes(self.name, Player.HistoryRound)
    return room:askForSkillInvoke(player, self.name, nil, "#emo__xinzhuang-invoke::"..target.id..":"..times+1)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@emo__xinzhuang-round")
    target:drawCards(3, self.name)
    local times = player:usedSkillTimes(self.name, Player.HistoryRound)
    room:askForDiscard(target, times, times, true, self.name, false)
  end,
}
moe__qianxueji:addSkill(emo__xinzhuang)

local emo__qinyue = fk.CreateActiveSkill{
  name = "emo__qinyue",
  frequency = Skill.Limited,
  anim_type = "support",
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function(self, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and target.gender ~= Self.gender and not target:isAllNude()
  end,
  prompt = function ()
    return "#emo__qinyue-prompt:::"..Self:usedSkillTimes("emo__xinzhuang", Player.HistoryRound)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:usedSkillTimes("emo__xinzhuang", Player.HistoryRound) > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local x = player:usedSkillTimes("emo__xinzhuang", Player.HistoryRound) 
    for _ = 1, x do
      if player.dead or target:isAllNude() then break end
      local id = room:askForCardChosen(player, target, "hej", self.name)
      local area = room:getCardArea(id)
      room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      if target.dead then break end
      if area == Card.PlayerEquip and target:isWounded() then
        room:recover { num = 1, skillName = self.name, who = target , recoverBy = player} 
      elseif area == Card.PlayerHand then
        target:drawCards(1, self.name)
      end
    end
  end,
}
moe__qianxueji:addSkill(emo__qinyue)

Fk:loadTranslationTable{
  ["moe__qianxueji"] = "千雪姬",

  ["emo__xinzhuang"] = "新妆",
  [":emo__xinzhuang"] = "一名角色使用装备牌后，你可令其摸三张牌，然后其弃置X张牌（X为本轮〖新妆〗发动次数）。",
  ["#emo__xinzhuang-invoke"] = "新妆：你可令 %dest 摸三张牌，然后其弃 %arg 张牌",
  ["@emo__xinzhuang-round"] = "新妆",
  
  ["emo__mingdao"] = "名刀",
  [":emo__mingdao"] = "锁定技，游戏开始时，将【无名刀】洗入牌库，你装备【无名刀】时使用【杀】无次数限制。每当一张装备牌于你的出牌阶段进入弃牌堆后，你摸一张牌。",

  ["emo__qinyue"] = "亲约",
  [":emo__qinyue"] = "限定技，出牌阶段，你可以依次获得一名其他角色角色区域内X张牌，以此法获得其装备区的一张牌后，令其回复1点体力，获得其一张手牌后，令其摸一张牌（X为本轮〖新妆〗发动次数）。",
  ["#emo__qinyue-prompt"] = "亲约：你可以连续获得一名其他角色角色区域内 %arg 张牌",

  ["$emo__qinyue1"] = "妾发初覆额，折花门前剧",
  ["$emo__qinyue2"] = "同居长干里，两小无嫌猜",
}

local moe__annite = General(extension, "moe__annite", "moe", 4, 4, General.Female)

local emo__tongshou = fk.CreateTriggerSkill{
  name = "emo__tongshou",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    local count = player.room:getTag("RoundCount")
    return player:hasSkill(self) and (count == 2 or count == 4 or count ==8)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = #room.alive_players
    room:changeMaxHp(player, x - player.maxHp)
    local y = x - player.hp
    if y > 0 then
      room:recover { num = y, skillName = self.name, who = player ,recoverBy = player}
    elseif y < 0 then
      room:loseHp(player, -y, self.name)
    end
  end,
}
moe__annite:addSkill(emo__tongshou)

local emo__kuiye = fk.CreateTriggerSkill{
  name = "emo__kuiye",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    local num = 0
    while true do
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|1~"..(24 - num),
        skipDrop = true, -- 判定后不进入弃牌堆
      }
      room:judge(judge)
      table.insert(cards, judge.card:getEffectiveId())
      num = num + judge.card.number
      if num > 24 or not room:askForSkillInvoke(player, self.name, nil, "#emo__kuiye-invoke:::"..num) then
        break
      end
    end
    cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if player.dead or num > 24 then
      room:moveCards({
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonJudge,
        skillName = self.name,
        proposer = player.id,
      })
    else
      local to = player
      local tos = player.room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#emo__kuiye-choose", self.name, true)
      if #tos > 0 then
        to = room:getPlayerById(tos[1])
      end
      room:obtainCard(to, cards, true, fk.ReasonGive, player.id, self.name)
    end
  end,
}
moe__annite:addSkill(emo__kuiye)

Fk:loadTranslationTable{
  ["moe__annite"] = "安妮特",

  ["emo__tongshou"] = "同寿",
  [":emo__tongshou"] = "锁定技，第二、四、八轮开始时，你将体力上限和体力值调整至X（X为存活角色数）。",
  ["emo__kuiye"] = "窥夜",
  [":emo__kuiye"] = "每当你受到伤害后，你可以进行一次判定，若X不大于24，你可以重复判定，或将这些判定牌交给一名角色；若X大于24，将这些牌置入弃牌堆（X为以此法判定的判定牌点数之和）。",
  ["#emo__kuiye-choose"] = "窥夜：你可以将这些牌交给一名角色；点“取消”：给自己",
  ["#emo__kuiye-invoke"] = "窥夜：你可以重复判定！（目前点数和：%arg）",
}

local moe__jiao = General(extension, "moe__jiao", "moe", 4, 4, General.Male)

local emo__youzhen = fk.CreateActiveSkill{
  name = "emo__youzhen",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  prompt = "#emo__youzhen-prompt",
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local generalPile = {}
    for _, name in pairs(room.general_pile) do
      local general = Fk.generals[name]
      if general.gender == General.Female and general.kingdom == target.kingdom then
        table.insert(generalPile, general)
      end
    end
    if #generalPile > 0 then
      local general = table.random(generalPile)
      if player.deputyGeneral == "moe__jiao" or player.tag["moe__jiao_deputy"] then
        -- 用player tag记录变身前此武将是否在副将
        player.tag["moe__jiao_deputy"] = true
        player.deputyGeneral = general.name
        room:broadcastProperty(player, "deputyGeneral")
      else
        player.general = general.name
        room:broadcastProperty(player, "general")
      end
      room:changeKingdom(player, general.kingdom, true)
    end
    player:drawCards(1, self.name)
  end,
}
moe__jiao:addSkill(emo__youzhen)

local emo__tongchou = fk.CreateTriggerSkill{
  name = "emo__tongchou",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target and target ~= player and not target.dead and player:hasSkill(self) and target.kingdom == player.kingdom
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.to ~= player then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(1, self.name)
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "defensive")
      room:doIndicate(player.id, {target.id})
      room:loseHp(target, 1, self.name)
    end
  end,
}
moe__jiao:addSkill(emo__tongchou)

local emo__ticong = fk.CreateTriggerSkill{
  name = "emo__ticong",
  frequency = Skill.Wake,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data) 
    return target.kingdom == player.kingdom and not (data.damage and data.damage.from and data.damage.from == player)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = {}
    player.general = target.general
    room:broadcastProperty(player, "general")
    for _, skill_name in ipairs(Fk.generals[target.general]:getSkillNameList()) do
      local skill = Fk.skills[skill_name]
      if not (skill.lordSkill and player.role ~= "lord") and (#skill.attachedKingdom == 0 or (table.contains(skill.attachedKingdom, player.kingdom))) then
        table.insertIfNeed(skills, skill_name)
      end
    end
    if #skills > 0 then
      room:handleAddLoseSkills(player, table.concat(skills, "|"))
    end
    room:handleAddLoseSkills(player, "-emo__youzhen")
  end,
}
moe__jiao:addSkill(emo__ticong)


Fk:loadTranslationTable{
  ["moe__jiao"] = "蛟",

  ["emo__youzhen"] = "游侦",
  [":emo__youzhen"] = "出牌阶段限一次，你可以将武将的图像变更为一名其他角色同势力的随机女性，然后摸一张牌。",
  ["#emo__youzhen-prompt"] = "游侦：选择一名其他角色，变装为与其同势力的女性，并摸一张牌",

  ["emo__tongchou"] = "同仇",
  [":emo__tongchou"] = "锁定技，与你同势力的其他角色造成伤害后，若受伤角色不为你，你摸一张牌，若为你，该角色失去1点体力。",

  ["emo__ticong"] = "替从",
  [":emo__ticong"] = "觉醒技，每当一名其他角色角色死亡时，若其势力与你相同，且伤害来源不为你，你获得其主将武将牌上的技能，并将图像替换为其，然后失去〖游侦〗。",

  ["$emo__ticong1"] = "将军的使命，由我完成",
  ["$emo__ticong2"] = "茫茫草芥，亦慕日月之皓",
}

local moe__chenyutong = General(extension, "moe__chenyutong", "moe", 3, 3, General.Female)

local emo__ranmo = fk.CreateTriggerSkill{
  name = "emo__ranmo",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed, fk.CardUsing, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TargetConfirmed then
        return data.card.suit == Card.Spade
      elseif event == fk.CardUsing then
        return data.card.suit == Card.Club
      else
        return player:getMark("@@emo__ranmo") ~= 0
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.TurnEnd then
      local room = player.room
      local targets = table.filter(room:getOtherPlayers(player), function (p) return p:getMark("@@emo__ranmo") == 0 end)
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, 
      "#emo__ranmo-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
    else
      self.cost_data = nil
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      local to = room:getPlayerById(self.cost_data.tos[1])
      room:setPlayerMark(to, "@@emo__ranmo", 1)
      room:setPlayerMark(player, "@@emo__ranmo", 0)
      room:addTableMark(to, "emo__ranmo_from", player.id)
      player:filterHandcards()
      to:filterHandcards()
    else
      player:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.BuryVictim, fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    if event == fk.BuryVictim then
      return player:getMark("@@emo__ranmo") > 0 and table.contains(player:getTableMark("emo__ranmo_from"), target.id)
    elseif event == fk.TurnEnd then
      return player:getMark("emo__ranmo_from") ~= 0
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.BuryVictim then
      -- 如果赠与者死亡，且没有其他赠与者，移除自己的标记
      room:removeTableMark(player, "emo__ranmo_from", target.id)
      if player:getMark("emo__ranmo_from") == 0 and not player:hasSkill(self) then
        room:setPlayerMark(player, "@@emo__ranmo", 0)
      end
    elseif event == fk.TurnEnd then
      if not player:hasSkill(self) then
        room:setPlayerMark(player, "@@emo__ranmo", 0)
      end
      for _, pid in ipairs(player:getTableMark("emo__ranmo_from")) do
        local from = room:getPlayerById(pid)
        if from:isAlive() and not from:hasSkill(self) then
          room:setPlayerMark(from, "@@emo__ranmo", 1)
          from:filterHandcards()
        end
      end
      room:setPlayerMark(player, "emo__ranmo_from", 0)
    end
    player:filterHandcards()
  end,

  on_acquire = function (self, player)
    player.room:setPlayerMark(player, "@@emo__ranmo", 1)
    player:filterHandcards()
  end,
  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@@emo__ranmo", 0)
    player:filterHandcards()
  end,
}

local emo__ranmo_filter = fk.CreateFilterSkill{
  name = "#emo__ranmo_filter",
  card_filter = function(self, card, player)
    return player:getMark("@@emo__ranmo") > 0 and card.color == Card.Red and table.contains(player.player_cards[Player.Hand], card.id)
  end,
  view_as = function(self, card)
    return Fk:cloneCard(card.name, card.suit == Card.Heart and Card.Spade or Card.Club, card.number)
  end,
}
emo__ranmo:addRelatedSkill(emo__ranmo_filter)

moe__chenyutong:addSkill(emo__ranmo)

local emo__qinshi = fk.CreateTriggerSkill{
  name = "emo__qinshi",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.color == Card.Black
    and not player:prohibitUse(Fk:cloneCard("slash"))
    and data.tos and table.find(TargetGroup:getRealTargets(data.tos), function (pid)
      local p = player.room:getPlayerById(pid)
      return p ~= player and not p.dead
    end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard("slash")
    slash.skillName = self.name
    local targets = table.filter(TargetGroup:getRealTargets(data.tos), function (pid)
      local p = player.room:getPlayerById(pid)
      return p ~= player and not p.dead and not player:isProhibited(p, slash)
    end)
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#emo__qinshi-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:askForDiscard(player, 2, 2, true, self.name, false, ".|.|.|.|.|basic")
    if not to.dead then
      room:useVirtualCard("slash", nil, player, to, self.name, true)
    end
  end,
}
moe__chenyutong:addSkill(emo__qinshi)

Fk:loadTranslationTable{
  ["moe__chenyutong"] = "陈雨桐",

  ["emo__ranmo"] = "染墨",
  [":emo__ranmo"] = "①你拥有“墨”标记，回合结束时，你可将之交给一名其他角色直到其回合结束；②拥有“墨”标记的角色手牌中的<font color='red'>♥</font>牌视为♠牌，<font color='red'>♦</font>牌视为♣牌；③每当你使用♣牌或成为♠牌的目标后摸一张牌。",
  ["#emo__ranmo-choose"] = "染墨：你可以将“墨”标记交给一名其他角色，直到其回合结束",
  ["@@emo__ranmo"] = "墨",
  ["#emo__ranmo_filter"] = "染墨",

  ["emo__qinshi"] = "侵势",
  [":emo__qinshi"] = "每当你对其他角色使用的黑色牌结算结束后，你可以弃置两张基本牌（无则不弃）并视为对其中一名目标角色使用一张【杀】。",
  ["#emo__qinshi-choose"] = "侵势，选择一名其他角色，弃置两张基本牌并视为对其使用【杀】",
}

local moe__kajiang = General(extension, "moe__kajiang", "moe", 4, 4, General.Female)

local emo__tianze = fk.CreateTriggerSkill{
  name = "emo__tianze",
  events = {fk.EventPhaseStart},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Start and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper),
    1, 1, "#emo__tianze-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local judge = { who = to, reason = self.name }
    room:judge(judge)
    if to.dead then return end
    if judge.card.type == Card.TypeEquip then
      if not to:hasDelayedTrick("lightning") and not table.contains(to.sealedSlots, Player.JudgeSlot) then
        local cid = judge.card:getEffectiveId()
        if room:getCardArea(cid) == Card.DiscardPile then
          room:useVirtualCard("lightning", cid, player, to, self.name)
        end
      end
    else
      local mark = to:getTableMark("@emo__tianze")
      if table.insertIfNeed(mark, judge.card:getTypeString().."_char") then
        room:setPlayerMark(to, "@emo__tianze", mark)
      end
    end
  end,

  refresh_events = {fk.DamageInflicted},
  can_refresh = function(self, event, target, player, data)
    if target ~= player or not data.card then return false end
    return table.contains(player:getTableMark("@emo__tianze"), data.card:getTypeString().."_char")
  end,
  on_refresh = function(self, event, target, player, data)
    data.damage = data.damage + 1
    player.room:removeTableMark(player, "@emo__tianze", data.card:getTypeString().."_char")
  end,
}

moe__kajiang:addSkill(emo__tianze)

local emo__qiming = fk.CreateTriggerSkill{
  name = "emo__qiming",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card and table.every(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).suit ~= data.card.suit
    end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if room:getCardArea(data.card) == Card.Processing then
      room:obtainCard(player, data.card, true, fk.ReasonJustMove, player.id, self.name)
    end
    room:retrial(Fk:getCardById(room:getNCards(1)[1]), player, data, self.name)
  end,
}

moe__kajiang:addSkill(emo__qiming)

Fk:loadTranslationTable{
  ["moe__kajiang"] = "佧酱",

  ["emo__tianze"] = "天责",
  [":emo__tianze"] = "准备阶段开始时，你可以令一名其他角色进行判定，其下次受到与判定牌类型相同的牌造成伤害+1，若为装备牌，将此牌当【闪电】对其使用。",
  ["@emo__tianze"] = "天责",
  ["#emo__tianze-choose"] = "天责：令一名其他角色进行一次判定，其下次受到与判定牌类型相同的牌造成伤害+1",

  ["emo__qiming"] = "欺命",
  [":emo__qiming"] = "锁定技，每当一名角色的判定牌生效前，若你没有此花色的手牌，你获得判定牌，并用牌堆顶牌代替之。",
}

local moe__xingying = General(extension, "moe__xingying", "moe", 4, 4, General.Female)

local emo__huzhao = fk.CreateTriggerSkill{
  name = "emo__huzhao",
  events = {fk.EventPhaseStart},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(4, self.name)
    local cards = room:askForDiscard(player, 4, 4, true, self.name, false, ".", "#emo__huzhao-discard")
    if #table.filter(cards, function (id) return Fk:getCardById(id).color == Card.Red end) % 2 == 0 and not player.dead then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__huzhao-choose", self.name, true)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        local mark = to:getTableMark("@@emo__huzhao")
        table.insert(mark, player.id)
        room:setPlayerMark(to, "@@emo__huzhao", mark)
        to:drawCards(4, self.name)
      end
    end 
  end,
}
local emo__huzhao_delay = fk.CreateTriggerSkill{
  name = "#emo__huzhao_delay",
  events = {fk.EventPhaseStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player == target and player.phase == Player.Play and player:getMark("@@emo__huzhao") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getMark("@@emo__huzhao")
    room:setPlayerMark(player, "@@emo__huzhao", 0)
    for _, fromId in ipairs(mark) do
      if player.dead or player:isNude() then break end
      local from = room:getPlayerById(fromId)
      if not from.dead then
        room:notifySkillInvoked(from, emo__huzhao.name, "support")
        room:doIndicate(fromId, {player.id})
      end
      room:askForDiscard(player, 4, 4, true, self.name, false)
    end
  end,
}
emo__huzhao:addRelatedSkill(emo__huzhao_delay)
moe__xingying:addSkill(emo__huzhao)

local QiyaoBanList = {"emo__qingyu", "emo__yuqing"}

local emo__qiyao = fk.CreateActiveSkill{
  name = "emo__qiyao",
  frequency = Skill.Limited,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  prompt = "#emo__qiyao-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local skills = {}
    for _, general_name in ipairs(room.general_pile) do
      local general = Fk.generals[general_name]
      for _, skill_name in ipairs(general:getSkillNameList()) do
        local skill = Fk.skills[skill_name]
        if not player:hasSkill(skill, true) and skill:isInstanceOf(TriggerSkill) and type(skill.events) == "table"
        and (table.contains(skill.events, fk.GameStart) or table.contains(skill.events, fk.GamePrepared))
        and not table.contains(QiyaoBanList, skill.name) then
          local str = Fk:translate(":"..skill_name)
          if string.find(str, "游戏开始时") then
            table.insertIfNeed(skills, skill_name)
          end
        end
      end
    end
    if #skills > 0 then
      local skill = Fk.skills[room:askForChoice(player, table.random(skills, 4), self.name, "#emo__qiyao-choice", true)]
      if not skill then return end
      room:handleAddLoseSkills(player, skill.name)
      local events = {fk.GamePrepared, fk.GameStart}
      for i = #events, 1, -1 do
        if not table.contains(skill.events, events[i]) then
          table.remove(events, i)
        end
      end
      for _, e in ipairs(events) do
        if skill:triggerable(e, player, player, nil) then
          skill:trigger(e, player, player, nil)
        end
      end
    end
  end,
}
moe__xingying:addSkill(emo__qiyao)

Fk:loadTranslationTable{
  ["moe__xingying"] = "星荧",
  ["#moe__xingying"] = "来自星尘",

  ["emo__huzhao"] = "互照",
  [":emo__huzhao"] = "出牌阶段开始时，你可以摸四张牌再弃置四张牌，若你弃置了偶数张红色牌，你可以令一名其他角色摸四张牌，若如此做，其出牌阶段开始时须弃置四张牌。",
  ["#emo__huzhao-choose"] = "互照：可令一名其他角色摸四张牌，其出牌阶段开始时弃置四张牌",
  ["#emo__huzhao-discard"] = "互照：弃置四张牌，若弃置偶数张红色牌，则可令一名其他角色摸四张牌并于其下个出牌阶段弃四张牌",
  ["#emo__huzhao_delay"] = "互照",
  ["@@emo__huzhao"] = "互照",

  ["emo__qiyao"] = "启耀",
  [":emo__qiyao"] = "限定技，出牌阶段，你可以从时机为“游戏开始时”的随机四个技能中选择一个，获得并触发此技能。",
  ["#emo__qiyao-choice"] = "启耀：选择一个技能并获得",
  ["#emo__qiyao-prompt"] = "启耀：你可以获得一个“游戏开始时”的技能并发动！",

  ["$emo__qiyao1"] = "此刻正是群星闪耀之时",
  ["$emo__qiyao2"] = "请星星指引我",
}

local moe__cangwu = General(extension, "moe__cangwu", "moe", 4, 4, General.Female)

local emo__jixing = fk.CreateTriggerSkill{
  name = "emo__jixing",
  events = {fk.EventPhaseStart, fk.TurnEnd},
  anim_type = "control",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local x, y = #room.draw_pile, #room.discard_pile
    if player:hasSkill(self) and target == player then
      if y > 2 * x then
        return player:getMark("emo__jixing_extra-round") == 0
      else
        return event == fk.EventPhaseStart and player.phase == Player.Start
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x, y = #room.draw_pile, #room.discard_pile
    if x > 2 * y then
      player:drawCards(1, self.name)
    elseif y > 2 * x then
      room:setPlayerMark(player, "emo__jixing_extra-round", 1)
      player:gainAnExtraTurn(false, self.name)
    else
      local cards = room:getNCards(10)
      room:moveCards({
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
      })
    end
  end,
}
moe__cangwu:addSkill(emo__jixing)

local emo__yushan = fk.CreateTriggerSkill{
  name = "emo__yushan",
  anim_type = "offensive",
  events = {fk.AfterCardsMove, fk.DamageCaused, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.DamageCaused then
      return target == player and player:getMark("@emo__yushan-turn") > 0 and player == player.room.current
    elseif event == fk.DamageInflicted then
      return target == player and player:getMark("@emo__yushan-turn") > 0 and player ~= player.room.current
    elseif player:isKongcheng() and table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and not p:isNude()
    end) then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      self.cost_data = {tos = {data.to.id}}
      return true
    elseif event == fk.DamageInflicted then
      self.cost_data = {}
      return true
    else
      local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__yushan-throw:::2", self.name, true)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      room:addPlayerMark(player, "@emo__yushan-turn", 1)
      local num = 2
      local to = room:getPlayerById(self.cost_data.tos[1])
      local cards = room:askForCardsChosen(player, to, 1, 2, "he", self.name)
      room:throwCard(cards, self.name, to, player)
      if #cards ~= 1 or player.dead then return end
      local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
      if #targets == 0 then return false end
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__yushan-throw:::1", self.name, true)
      if #tos > 0 then
        to = room:getPlayerById(tos[1])
        cards = room:askForCardsChosen(player, to, 1, 1, "he", self.name)
        room:throwCard(cards, self.name, to, player)
      end
    elseif event == fk.DamageCaused then
      data.damage = data.damage + player:getMark("@emo__yushan-turn")
      room:setPlayerMark(player, "@emo__yushan-turn", 0)
    else
      data.damage = data.damage - player:getMark("@emo__yushan-turn")
      room:setPlayerMark(player, "@emo__yushan-turn", 0)
    end
  end,
}
moe__cangwu:addSkill(emo__yushan)

Fk:loadTranslationTable{
  ["moe__cangwu"] = "苍雾",
  ["#moe__cangwu"] = "雾隐仙子",

  ["emo__jixing"] = "急行",
  [":emo__jixing"] = "锁定技，若X>2Y，准备阶段你摸一张牌，若Y>2X，回合结束后你执行一个额外回合（每轮限一次）。其他情况，准备阶段你将牌堆顶十张牌置入弃牌堆（X为摸牌堆牌数，Y为弃牌堆牌数）。",

  ["emo__yushan"] = "御扇",
  [":emo__yushan"] = "当你失去最后手牌时，你可以弃置其他角色至多两张牌，若为你回合内，本回合你下次造成伤害+1，若为回合外，本回合你下次受到伤害-1。",
  ["#emo__yushan-throw"] = "御扇：你可以弃置其他角色至多 %arg 张牌",
  ["@emo__yushan-turn"] = "御扇",
}

local moe__misheng = General(extension, "moe__misheng", "moe", 4, 4, General.Female)

local emo__lishi = fk.CreateTriggerSkill{
  name = "emo__lishi",
  events = {fk.GameStart, fk.CardUseFinished, fk.TurnStart, fk.TurnEnd},
  frequency = Skill.Quest,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:getQuestSkillState(self.name) or not player:hasSkill(self) then return false end
    if event == fk.GameStart then
      return true
    elseif event == fk.CardUseFinished then
      return data.card.type ~= Card.TypeBasic and (target ~= player or player:getMark("@emo__lishi") > 1)
    elseif event == fk.TurnStart then
      return player == target and player:getMark("@emo__lishi") > #player.room.alive_players * 3
    else
      return player == target and player:getMark("@emo__lishi") == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      room:notifySkillInvoked(player, self.name)
      room:addPlayerMark(player, "@emo__lishi", 2)
    elseif event == fk.CardUseFinished then
      if target ~= player then
        room:addPlayerMark(player, "@emo__lishi")
      else
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:drawCards(1, self.name)
        room:removePlayerMark(player, "@emo__lishi", 2)
      end
    elseif event == fk.TurnStart then -- 成功
      room:setPlayerMark(player, "@emo__lishi", 0)
      room:notifySkillInvoked(player, self.name, "big")
      room:updateQuestSkillState(player, self.name)
      room:changeMaxHp(player, 1)
      if not player.dead and player:isWounded() then
        room:recover { num = 1, skillName = self.name, who = player, recoverBy = player}
      end
      room:handleAddLoseSkills(player, "emo__zhuojian")
    else -- 失败
      room:notifySkillInvoked(player, self.name, "drawcard")
      room:updateQuestSkillState(player, self.name, true)
      player:drawCards(3, self.name)
      if not player:isNude() then
        room:recastCard(player:getCardIds("he"), player, self.name)
      end
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@emo__lishi", 0)
  end,
}
moe__misheng:addSkill(emo__lishi)

local emo__zhuojian = fk.CreateTriggerSkill{
  name = "emo__zhuojian",
  anim_type = "control",
  events = {fk.EventPhaseStart, fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.EventPhaseStart then
      return target == player and player.phase == Player.Start
    elseif target == player and not player.dead then
      local mark = player:getTableMark("@emo__zhuojian-turn")
      return table.contains(mark, data.card:getTypeString().."_char")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local mark = {}
      local all_choices = {"basic", "trick", "equip"}
      local choices = table.simpleClone(all_choices)
      for i = 1, 2 do
        local choice = room:askForChoice(player, choices, self.name, "#emo__zhuojian-choice"..i, false, all_choices)
        table.removeOne(choices, choice)
        table.insert(mark, choice.."_char")
      end
      room:setPlayerMark(player, "@emo__zhuojian-turn", mark)
    else
      local mark = player:getTableMark("@emo__zhuojian-turn")
      if data.card:getTypeString().."_char" == mark[1] then
        player:drawCards(1, self.name)
      else
        local targets = room:getOtherPlayers(player, false)
        if #targets == 0 then return false end
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__zhuojian-throw", self.name, false)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          if not to:isNude() then
            room:throwCard(table.random(to:getCardIds("he"), 1), self.name, to, player)
          end
        end
      end
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@emo__zhuojian-turn", 0)
  end,
}
moe__misheng:addRelatedSkill(emo__zhuojian)

Fk:loadTranslationTable{
  ["moe__misheng"] = "弥生",

  ["emo__lishi"] = "历世",
  [":emo__lishi"] = "使命技：游戏开始时，你获得2个“历”标记；每当其他角色使用非基本牌后，你获得1个“历”标记；你使用非基本牌后，若你至少有2个“历”标记，摸一张牌并失去2个“历”标记。<br>"..
  "<strong>成功</strong>：回合开始时，若你的“历”标记数大于存活角色数的三倍，你增加一点体力上限并回复一点体力，然后获得技能〖灼见〗。<br>"..
  "<strong>失败</strong>：回合结束时，若你没有“历”标记，你摸三张牌，然后重铸所有牌。",
  ["@emo__lishi"] = "历",
  ["$emo__lishi1"] = "",
  ["$emo__lishi2"] = "",

  ["emo__zhuojian"] = "灼见",
  [":emo__zhuojian"] = "锁定技，准备阶段，你选择两种不同的类型，本回合中：你使用你选择的第一种类型的牌时摸一张牌，你使用第二种类型的牌时，你弃置一名其他角色随机一张牌。",
  ["@emo__zhuojian-turn"] = "灼见",
  ["#emo__zhuojian-choice1"] = "灼见：选择一种类型，你使用时摸一张牌",
  ["#emo__zhuojian-choice2"] = "灼见：选择一种类型，你使用时弃置其他角色随机一张牌",
  ["#emo__zhuojian-throw"] = "灼见：请选择一名其他角色，随机弃置其一张牌",
}

local moe__xufeng = General(extension, "moe__xufeng", "moe", 4, 4, General.Female)

local emo__yuhu = fk.CreateTriggerSkill{
  name = "emo__yuhu",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if not player:hasSkill(self) then return false end
    if event == fk.TurnStart then 
      local max_num = 0
      for _, p in ipairs(room.alive_players) do
        max_num = math.max(max_num, p.hp)
      end
      return target.hp == max_num and not table.contains(target.sealedSlots, Player.TreasureSlot)
      and not table.find(target:getEquipments(Card.SubtypeTreasure), function(cid) return Fk:getCardById(cid).name == "whitefox" end)
    else
      for _, move in ipairs(data) do
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).name == "whitefox" then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      player:drawCards(1, self.name)
    else
      local cardId = MoeFunc.getDerivedCard(room, "whitefox")
      if cardId and room:getCardArea(cardId) ~= Card.PlayerSpecial then
        local from = room:getCardOwner(cardId)
        if from and from ~= target then
          room:doIndicate(from.id, {target.id})
        end
        room:moveCardIntoEquip(target, cardId, self.name, true, player)
      end
    end
  end,
}
moe__xufeng:addSkill(emo__yuhu)

Fk:loadTranslationTable{
  ["moe__xufeng"] = "徐风",
  
  ["emo__yuhu"] = "御狐",
  [":emo__yuhu"] = "锁定技，任意角色的回合开始时，若其体力值为最多之一，将【白狐】置入其装备区（替换原装备）。每当【白狐】移动时你摸一张牌。【白狐】对你造成伤害可转移给其他角色。<br>"..
  "<font color='grey'>【白狐】装备牌·宝物（衍生牌）<br/><b>宝物技能</b>：锁定技，出牌阶段开始时，你视为使用【酒】，然后受到1点伤害。",
}

local moe__suofeiya = General(extension, "moe__suofeiya", "moe", 4, 4, General.Female)

local emo__yinglue = fk.CreateActiveSkill{
  name = "emo__yinglue",
  anim_type = "offensive",
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  prompt = "#emo__yinglue",
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    local winner = pindian.results[target.id].winner
    local n = math.abs(pindian.fromCard.number - pindian.results[target.id].toCard.number)
    if player == winner then
      if n > 5 then
        U.askForUseVirtualCard(room, player, "slash", nil, self.name, nil, true, true, true, true)
        U.askForUseVirtualCard(room, target, "slash", nil, self.name, nil, true, true, true, true)
      else
        player:addSkillUseHistory(self.name, -1)
      end
    else
      if n > 5 then
        if player.dead then return end
        room:damage { from = target, to = player, damage = 1, skillName = self.name }
      else
        if not player.dead then player:drawCards(2, self.name) end
        if not target.dead then target:drawCards(2, self.name) end
      end
    end
  end,
}

moe__suofeiya:addSkill(emo__yinglue)

local emo__yijian = fk.CreateTriggerSkill{
  name = "emo__yijian$",
  events = {fk.EventPhaseStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and target.phase == Player.Discard and target.kingdom == "moe"
  end,
  on_cost = function (self, event, target, player, data)
    local choices = {"emo__yijian_maxcard"}
    if not target:isNude() then table.insert(choices, "emo__yijian_recast") end
    table.insert(choices, "Cancel")
    local choice = player.room:askForChoice(target, choices, self.name, "#emo__yijian-invoke:"..player.id)
    if choice ~= "Cancel" then
      self.cost_data = {choice = choice, tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = self.cost_data.choice
    if choice == "emo__yijian_maxcard" then
      room:addPlayerMark(target, MarkEnum.AddMaxCards)
      if player:isNude() then return end
      local cards = room:askForCard(player, 1, 1, true, self.name, false, ".", "#emo__yijian-recast")
      if #cards > 0 then
        room:recastCard(cards, player, self.name)
      end
    else
      local cards = room:askForCard(target, 1, 1, true, self.name, false, ".", "#emo__yijian-recast")
      if #cards > 0 then
        room:recastCard(cards, target, self.name)
      end
      room:addPlayerMark(player, MarkEnum.AddMaxCards)
    end
  end,
}

moe__suofeiya:addSkill(emo__yijian)

Fk:loadTranslationTable{
  ["moe__suofeiya"] = "索菲亚",
  
  ["emo__yinglue"] = "英略",
  [":emo__yinglue"] = "出牌阶段限一次，你可以与一名其他角色拼点：若你赢，且点数之差大于5，你与其依次视为使用一张【杀】，若不大于5，视为未发动过〖英略〗；若你没赢，且点数之差大于5，你受到其造成的1点伤害，若不大于5，你与其各摸两张牌。",
  ["#emo__yinglue"] = "与其他角色拼点：若赢且点数差>5，你与其视为使用【杀】；若没赢且点数差>5，你受到伤害",

  ["emo__yijian"] = "易见",
  [":emo__yijian"] = "主公技，其他萌势力角色的弃牌阶段开始时，其可以选一项：1.手牌上限+1；2.重铸一张牌。然后你执行另一项。",
  ["emo__yijian_maxcard"] = "手牌上限+1",
  ["emo__yijian_recast"] = "重铸一张牌",
  ["#emo__yijian-invoke"] = "你可以发动 %src 的“易见”：你选择一项执行，令其执行另一项",
  ["#emo__yijian-recast"] = "易见：重铸一张牌",
}

local moe__tangci = General(extension, "moe__tangci", "moe", 4, 4, General.Female)

local emo__qiaoyu = fk.CreateTriggerSkill{
  name = "emo__qiaoyu",
  anim_type = "control",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target ~= player and not player:isKongcheng() and target == player.room.current
    and data.tos and data.card.type ~= Card.TypeEquip then
      local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data[1]
        return use and use.from == target.id and use.card.type == data.card.type
      end, Player.HistoryTurn)
      return #events > 0 and events[1].data[1] == data
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local pattern = table.contains(TargetGroup:getRealTargets(data.tos), player.id) and "equip" or "trick"
    local use = U.askForUseRealCard(room, player, nil, ".|.|.|.|.|"..pattern, self.name, "#emo__qiaoyu-"..pattern..":::"..data.card:toLogString(), nil, true)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    local current_targets = TargetGroup:getRealTargets(data.tos)
    if table.contains(current_targets, player.id) then
      TargetGroup:removeTarget(data.tos, player.id)
    else
      local to = #current_targets == 1 and current_targets[1] or
      room:askForChoosePlayers(player, current_targets, 1, 1, "#emo__qiaoyu-choose:::"..data.card:toLogString(), self.name, false)[1]
      TargetGroup:removeTarget(data.tos, to)
    end
    room:useCard(use)
  end,
}

moe__tangci:addSkill(emo__qiaoyu)

Fk:loadTranslationTable{
  ["moe__tangci"] = "唐瓷",

  ["emo__qiaoyu"] = "巧御",
  [":emo__qiaoyu"] = "每当一名其他角色于其回合内使用第一张基本牌及第一张锦囊牌时，若目标含有你，你可以使用手牌中一张装备牌，令目标取消你；若目标不含有你，你可以使用手牌中一张锦囊牌，取消一个目标。",
  ["#emo__qiaoyu-equip"] = "巧御：你可使用一张装备牌，令 %arg 目标取消你",
  ["#emo__qiaoyu-trick"] = "巧御：你可使用一张锦囊牌，取消 %arg 的一个目标",
  ["#emo__qiaoyu-choose"] = "巧御：请取消 %arg 的一个目标",
}


local moe__liou = General(extension, "moe__liou", "moe", 4, 4, General.Female)

local emo__emo = fk.CreateActiveSkill{
  name = "emo__emo",
  mute = true,
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  prompt = "#emo__emo-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 and player.hp < 10
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:notifySkillInvoked(player, self.name, "offensive")
    player:broadcastSkillInvoke(self.name, 1)
    local generalPile = room.general_pile
    if #generalPile == 0 then return false end
    local name = room:askForGeneral(player, table.random(generalPile, 8), 1, true)
    if type(name) == "table" then name = name[1] end
    table.removeOne(room.general_pile, name)
    local general = Fk.generals[name]

    room:sendLog{ type = "#EatGeneral", from = player.id, arg = general.name, }
    room:broadcastPlaySound("./packages/"..general.package.extensionName.."/audio/death/"..general.name)
    room:delay(500)
    room:changeMaxHp(player, general.maxHp)
    if not player.dead and player:isWounded() then
      room:recover({ who = player,  num = general.hp, skillName = self.name })
    end
    room:changeShield(player, general.shield)
    if player.dead then return end
    for _, skill in ipairs(general:getSkillNameList(true)) do
      local n = #Fk:translate(":"..skill) / 3
      room:addPlayerMark(player, "mo__emo_count", math.ceil(n))
    end
    local x = math.floor(player:getMark("mo__emo_count")/100)
    if x > 0 then
      player:drawCards(x, self.name)
    end
    room:setPlayerMark(player, "mo__emo_count", player:getMark("mo__emo_count")%100)
  end,
}

local emo__emo_trigger = fk.CreateTriggerSkill{
  name = "#emo__emo_trigger",
  mute = true,
  events = {fk.DamageInflicted, fk.Damaged},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.DamageInflicted then
        return player:getMark("@emo__emo") > 0
      else
        return player:getMark("emo__emo_invoked-turn") == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      data.damage = data.damage + player:getMark("@emo__emo")
      room:notifySkillInvoked(player, "emo__emo", "negative")
      player:broadcastSkillInvoke("emo__emo", 2)
    else
      room:addPlayerMark(player, "@emo__emo")
      room:addPlayerMark(player, "emo__emo_invoked-turn")
    end
  end,
}
emo__emo:addRelatedSkill(emo__emo_trigger)

moe__liou:addSkill(emo__emo)

Fk:loadTranslationTable{
  ["moe__liou"] = "莉欧大魔王",
  ["#moe__liou"] = "真的是大魔王哦",
  
  ["emo__emo"] = "饿魔",
  [":emo__emo"] = "①出牌阶段限一次，若你体力值小于10，你可以从八张武将牌中选择并吞吃一张，获得其体力上限、体力值与护甲值，并记录其技能描述，每超过100字你摸一张牌。②你受到的伤害值+0，每回合一次，当你受到伤害后，此值+1。",
  ["mo__emo_count"] = "饿魔",
  ["@emo__emo"] = "饿魔",
  ["#emo__emo_trigger"] = "饿魔",
  ["#EatGeneral"] = "%arg 被 %from 吃掉了！",
  ["#emo__emo-prompt"] = "饿魔:你可以吃掉一个武将!",

  ["$emo__emo1"] = "我吃！我吃！我吃吃吃！",
  ["$emo__emo2"] = "尔等，竟如此歹毒！",
}




return extension
